Static Assets: How to deploy a SPA?

Currently I'm using remix with spa mode and deploying it to cf workers, I also have Hono as main entrypoint for my bucket, problem is when i go to the root (/) I do get served the index.html file and if I navigate using the <Link> component everything goes well, but if i refresh in a path other than / I get 404. Should rewrite the requests with Hono? Is there a similar thing as behaviour in cloudfront where you can specify a certain path always serve a static file?
5 Replies
martin
martinOP•3w ago
hey, thank you for the speedy answer!. I did set up that however it's not working as expected, could it be that i'm providing a main handler (hono) and that takes precedent over that setting? I can package it into a minimum reproducible example and share a git repo with you if you want!
martin
martinOP•3w ago
yeah that's what i thought, i tried doing something like that but i got an error, how could i serve the index.html (can confirm it's hono, just added a header to verify)
No description
martin
martinOP•3w ago
got error code 1042 ah THANK YOU, this works beautifully!! i didn't find that c.env.ASSET.fetch anywhere so fast man, cloudflare is the best 🔥
martin
martinOP•3w ago
good to know, yeah this is what i had + the hono part i shared and an index.html generated by remix, pretty simple just trying out a POC
No description
martin
martinOP•3w ago
yeah i just wanted to have a good hono + remix setup in a single worker, would you suggest having remix as a spa in one worker and hono separately? yeah that makes sense, i guess it's just convenient to have it altogether for smaller projects but for big ones i'll definitely keep that in mind, thanks man. if i could ask for a feature it'd be nice to have something like cloudfront's cache behaviours where i could say /api/* is handled by hono and all the rest is static assets so just handle it as a spa. i think having it all in one worker is super convenient to have the backend and frontend deployed at the same time + no need for a monorepo setup or something like that yes, will do 🫡
Want results from more Discord servers?
Add your server