What kind of Caddyfile configuration do I need to serve a react app (created with create-react-app) with react-router correctly? Basically, domain.com/app/
(this is the root of the app) should redirect to index.html
, domain.com/app/sub
should redirect to index.html
(routing will be done on frontend by react-router), but then again for example domain.com/app/manifest.json
should not redirect to anywhere since it's an actual file that needs to be served. Then there's also domain.com/app/static/
url which should be served as is.
My current Caddyfile:
domain.com/app {
root /server/public/app
rewrite / {
to {path} /
}
}
This kind of works, but it also redirects domain.com/app/manifest.json
and all domain.com/app/static/
urls too.
How to tell Caddy to look for a file in the path and if it doesn't exist then redirect to the root? The docs imply this is how the rewrite block should work, but there is something wrong in my configuration file because it does not seem to work.
I have tried many examples already but they all also redirect the /static/ folder and manifest.json etc too.