server {
    listen      80;
    server_name localhost;
    charset utf-8;
    root    /home/radxa/aide-plus/frontend/dist;
    index   index.html;

    # API proxy to backend
    location /api/ {
        proxy_pass http://localhost:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 10s;
        proxy_send_timeout 10s;
        proxy_read_timeout 10s;
    }

    # index.html names the hashed bundle of the current build, and apply-update deletes the
    # previous build's files: Chromium must revalidate it every time. A cached copy pointing
    # at a deleted bundle gave a white screen. "/" and the SPA fallback both land here.
    location = /index.html {
        add_header Cache-Control "no-cache";
    }

    # Hashed build files never change. A missing one must fail as a 404, not come back as
    # index.html with a 200 (Chromium then refuses it as a script and the app never starts)
    location /assets/ {
        try_files $uri =404;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }

    # Serve static files and SPA routing
    location / {
        try_files $uri $uri/ /index.html;
    }

    error_log  /var/log/nginx/vue-app-error.log;
    access_log /var/log/nginx/vue-app-access.log;
}
