I have a little issue which I'm not really certain...
# kobweb
c
I have a little issue which I'm not really certain what the issue is, but it could well be that it's something about static pages that I'm not really grasping correctly. The site I'm building has this kinda structure (see picture) When on the Home page, the user is shown some projects, and upon clicking on one, can navigate to the detail page with route
/projects/?projectId=2
. Running kobweb locally serves the correct page with the correct information. But when exported to a static site I just get a white page with
Error 404
on it. However... my homepage has the ability to fetch specific category of projects with path
/?categoryId=2
and that one route does work, both locally and when exported to static files... Is this an issue because a static can not have query parameters? Or should I be looking at another issue? πŸ€” What I understood that a static site could not support was dynamic paths like
/projects/{projectId}/
, so I'm a bit lost I'm afraid πŸ˜…
d
Are you opening the html file directly from the file system? Or using
kobweb run
?
Also I don't understand the context of the picture you shared. Is that under
.kobweb
? In your site resources?
c
Sorry, the context of the picture is the site I'm serving in my ktor project πŸ˜… I created a kobweb project and a separate ktor project to learn both at my own pace. And am serving the exported static site with
staticFiles("/", File("site"))
in ktor. I omitted the
.js
and
.js.map
files in this snippet
d
Ah OK got it!
/projects/?projectId=2
should work
Your mental model is correct
How are you testing the website running after a static export?
c
Not sure If I understood your question correctly, but after a static export. I import it in my ktor project, at root level (just the
site
folder) and then tell ktor to serve it by using
staticFiles("/", File("site"))
After that I run ktor locally and just navigate to
localhost:8080
and just use the site like normal. When I notice that my link to the detail page does not work, I try out some other versions of the path. For example:
/projects?projectId=2
or
/projects/projectId=2
and also
/projects
. The last one actually renders my page, but because it doesn't find a parameter it won't show the correct data. The other 2 just give an error. The first one just gives a white page with
Error 404
(which I think is just an error of ktor itself?). The second one gives another error stating
No web page was found for the web address: localhost:8080*/projects/?projectId=2*
d
I was making sure you weren't just opening
index.html
directly 😜
c
Ooh I tried that as well but learned that it does not work that way xD
d
Yep
So it's possible you need to handle index.html yourself
c
Hmm, okay? And how what I do that? Is there some sample/example that I can take a look at? πŸ˜…
I'm not doing that in Kobweb though so I'm not 100% sure
I have a comment that looks like this:
Copy code
// "example/" should resolve to "example/index.html" if present, but default ktor behavior rejects trailing slashes.
this.install(IgnoreTrailingSlash)
(where
this
is an
Application
)
Let me double check that this is actually working on Kobweb πŸ•΅οΈβ€β™‚οΈ
c
Hmm I might have to test some more things, but at first glance that handling of
index.html
doesn't seem to work πŸ˜… Also, would it mabye be needed to have every folder as a separate staticFile like this? πŸ€”
Copy code
staticFiles("/", File("site"), index = "index.html")
staticFiles("/projects", File("site/projects"), index = "index.html")
And that about the trailing slash is nice to know!
d
Static export kobweb server seems to work
Not sure why!
I'll see if the trailing slash change breaks it
Meeting coming up in 4 minutes in case I disappear
c
Haha, not a problem, take your time!! πŸ˜„
Erm... Okay very strange... After adding this plugin
this.install(IgnoreTrailingSlash)
, this path actually works
<http://localhost:8080/projects/?projectId=1>
πŸ€” πŸ˜… And trying out this path
<http://localhost:8080/projects?projectId=1>
(without trailing slash), actually show the page for a split second and then just plainly shows
Error code: 404
on a white page πŸ˜… Update: When deploying it to Render I had to use
staticResources("/", "/static/site")
. For some reason
staticFiles(...)
wasn't serving any files... Could've been my fault, but for now it works and it's okay. Gonna take another look at it some other time! Thanks for thinking with me and providing me with the trailingSlash fix! πŸ˜…
d
Glad you're working!
c
Nice! Even though this works now, I'm sure if I want to keep it this way. I'm thinking about trying to get them both in the same repository and updating the Dockerfile to build both the ktor and the kobweb project on a server. As far as I understand, this should work as I'm able to do so on my local machine by running them both on localhost but on a different port... πŸ€” But that's something for another time πŸ˜„
d
I mean it should be doable
I suspect you've seen my Dockerfile example: https://bitspittle.dev/blog/2023/clouddeploy#add-a-dockerfile
I'm sure you can find a ktor Dockerfile example and use that instead
Frankenstein the two parts together πŸ™‚
c
Hmm thanks for the info! That should be a nice start for me to investigate! πŸ˜„