[Docker] Help with react-router paths

1. The problem I’m having:

I have a dockerized react-vite app using react-router-dom, my domain name is https://nascent.dev.
When I try to access paths such as /library or /chapter (so https://nascent.dev/library) for example I get the page I am looking for, but the problem arises when I refresh the page or try to access it using the URL I get a blank page with a 404 error.

I looked into it and it was recommended to append file_server to the Caddyfile or even the try_files {path} /index.html command but unfortunately I don’t know how I can do this with a containerized environment.

2. Error messages and/or full log output:

404 - The requested path could not be found

3. Caddy version:


a. System environment:

docker ubuntu, stack: react, react-router, vite

b. Caddyfile:

nascent.dev {
    reverse_proxy nascent-frontend:8080 {
        header_down Strict-Transport-Security max-age: 31536000

c. docker-compose.yml file:

version: '3'

    container_name: nascent-api 
    restart: unless-stopped
      context: ./bai
      dockerfile: Dockerfile
      - "3000:3000"

    container_name: nascent-frontend 
    restart: unless-stopped
      context: ./mythril
      dockerfile: Dockerfile
      - "8080:8080"

    image: caddy/caddy:2.7.5-alpine
    container_name: caddy-nascent
    restart: unless-stopped
      - "80:80"
      - "443:443"
    - $PWD/Caddyfile:/etc/caddy/Caddyfile
    - $PWD/site:/srv
    - caddy_data:/data
    - caddy_config:/config


Yeah, try_files can only be used when Caddy has access to the files, but you’re using reverse_proxy here so that’s not possible.

You’ll need to configure your upstream server. I think you need to configure appType. See Shared Options | Vite

1 Like

Wow, I feel so dumb right now. I was using the npm package serve to have my front-end running which caused all this.

Thank you for highlighting that the problem might be related to vite rather than Caddy otherwise I’d have unnecessarily spend more time on it! lol

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