# nginx for the docker stack — HTTP only on :2000. TLS + domain are handled by
# the user's OWN reverse proxy placed in front of this container; this just serves
# the SPA and reverse-proxies the API to the backend.
server {
    listen 2000;
    listen [::]:2000;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;

    client_max_body_size 50m;

    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;

    # video / large-image generation can block minutes — avoid the 60s 504.
    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;

    # Hashed build assets never change — cache hard.
    location /assets/ {
        expires 1y;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }

    # SPA fallback; index.html must never be cached (else stale bundle hash).
    location / {
        try_files $uri $uri/ /index.html;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
    }

    # ---- API / media / health -> backend ----
    location ^~ /admin/api/ { proxy_pass http://backend:6666; add_header Cache-Control "no-store" always; }
    location ^~ /images/    { proxy_pass http://backend:6666; }
    location = /health      { proxy_pass http://backend:6666; }
    # /v1 is per-API-key authenticated — never cache.
    location ^~ /v1/ {
        proxy_pass http://backend:6666;
        add_header Cache-Control "no-store" always;
    }
}
