# Serves the built Vue SPA and reverse-proxies API/FHIR calls to the api
# container so the frontend's relative-URL Axios clients (baseURL "/api/v1" and
# "/fhir") work unmodified in production — mirrors the Vite dev server proxy in
# vite.config.ts, just pointed at the "api" service name instead of localhost.

server {
    listen 80;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;

    client_max_body_size 30m; # scanned document uploads (25 MB max) plus overhead

    location /api/ {
        proxy_pass http://api:8080;
        proxy_http_version 1.1;
        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;
    }

    location /fhir/ {
        proxy_pass http://api:8080;
        proxy_http_version 1.1;
        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;
    }

    # SPA history-mode fallback
    location / {
        try_files $uri $uri/ /index.html;
    }
}
