I am trying to serve a react application that utilizes react router using Caddy.
Caddyfile:
subdomain
redir /ui /ui/
handle_path /ui/* {
root * /app/build/
file_server
}
Relevant portions of the docker-compose:
caddy:
image: img
restart: always
network_mode: bridge
container_name: caddyContainer
ports:
- "443:443"
- "80:80"
env_file:
- ./CaddyEnv.env
volumes:
- caddy_data:/data
- caddy_config:/config
- ./Caddyfile:/etc/caddy/Caddyfile
and my package.json file begins:
"name": "name",
"version": "0.1.0",
"homepage": "/ui/",
...
}
This lets it know it starts from “/ui/”.
React router seems to be working because when I go to localhost/ui/check (one of my react router routes), it renders correctly. However when I put it up using Caddy and route to subdomain/ui/check, I get a 404 page cannot be found.
I saw something online about “try files”, but I was not sure if that was what I wanted, because it does not seem to be a dynamic approach. Maybe I misunderstood?