I've exported and deployed a static site with some...
# kobweb
c
I've exported and deployed a static site with some markdown pages following the default example. I'm getting 404 responses when accessing those pages (https://my-app.com/about). However, if I go to my home page then click on a link to navigate there ( go to https://my-app.com then click on a link for https://my-app.com/about).... the pages are found! Curious if this sounds like an export configuration I'm missing in kobweb, or if I'm just having DNS issues
d
kobweb export --layout static
?
What's your hosting provider?
c
kobweb export --layout static
- yea that's the one! I'm using Digital Ocean's App Platform
d
Usually a 404 in the way you're deciding means a static hosting provider combined with a fullstack layout, huh. Can you check the final files as uploaded to their platform? I'd want to verify that a top level file named
about.html
is there.
👀 1
I'm not familiar with Digital Ocean but maybe it's not configured correctly I'd guess
So double check that?
Basically both static and fullstack layouts output a root
index.html
file so that's almost definitely what is being downloaded when you visit your site without the
about
part.
Once things are downloaded locally, then yeah you can navigate around without ever revisiting the server -- this is the power of something like Kobweb. You get an initial download and after that everything is local and instant to run.
That's why you can link to the
about
route in that case, because everything is downloaded. But when you visit the url, at that point you're asking the server for the initial file to download, and it says it doesn't have it
c
hmm seems like it is uploading the pages (such as about.html)
d
That's good!
Check your server setup then, that's my current suspicion
Also, you should open up the network dev tools panel and then visit the
about
URL
Maybe there will be some insight there into what is going wrong
(I think you have to toggle recording on inside the UI somewhere, with chrome)
c
Interesting... seems like Digital Ocean doesn't support wildcard rewrites (nor did it throw any errors about it) I had to add a rewrite for each page like
/about -> /
whereas before I was trying
/* -> /
d
Just set that to index.html and move on with your life! 🙂
👍 1
c
nice recommendation! How do you reckon I handle actual 404's for pages I don't have, so that I don't end up with a reload loop?
d
You'll download the index file and then Kobweb will show a 404 itself (if a route is invalid)
👍 1
The default error UI is pretty minimal but you can customize it
c
Ok interesting, my reload loops were actually coming from an uncaught error
Copy code
qu {message: "Call 'navigateTo' at least once before calling 'renderActivePage'", cause: undefined, name: 'qu', stack: "qu: Call 'navigateTo' at least once before calling…  at A (<https://swell-scope.com/site.js:1:524631>)"}
d
Ah
That's tricky to debug. I'm trying to remember what that might be
I feel like I wouldn't have expected a user to see that
c
just seeing that in the console, but results in rerequesting the page again seems like
d
The error comes from here: https://github.com/varabyte/kobweb/blob/a694950e0301f6f42f130ac4ccef3acd3e9c7c0d/frontend/kobweb-core/src/jsMain/kotlin/com/varabyte/kobweb/navigation/Router.kt#L237 and basically means you are trying to render a page before the system ever even visited the first page.
Kobweb is supposed to do this for you, unless you're not actually depending on Kobweb directly but are setting things up manually
So if you've built your site locally, you can search for
main.kt
under your
build
folder, it will be in a
generated
subfolder
You can find that it calls
tryRoutingTo
which satisfies the
navigateTo
part of the error message. You can also see how it sets up calls to
renderActivePage
in there.