On browser reload spa throws 404 on current route instead of reloading root

I am serving a quasar/vuejs spa. When a user is on any route (url) and they refresh the browser the entire the root layout page is loaded and I direct them back to the home page instead. I do this cause a browser refresh is a call to load all the data from multiple web sockets. This works great in the quasar dev server but when I serve from caddy I am thinking that caddy (given my stanza below) thinks this is just a static site (ie. root directive) and thus reloads the “static” page url which throws a 404.

Is there a way to make caddy behave like my dev server? reload the root on browser reload no matter the current url/route? some spa aware directive instead of root?

(worse case I think I can force this using window beforeunload event to change the route back to /. I would have to add this to every route/page via a mixin. I’d rather not).

using Caddy v1

https://lights.xxxx.net {
        import wildcard_cert
        root /mnt/data/webs/lights-frontend
        proxy /socket.io {

You’ll want to use a rewrite for this https://caddyserver.com/v1/docs/rewrite

rewrite not /socket.io /

This will rewrite any URL that does not start with /socket.io to /

I strongly recommend using Caddy v2 though, as Caddy v1 is no longer being supported (only security fixes for a certain amount of time)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.