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

    # Use Docker's embedded DNS with 30s TTL so upstream IPs refresh
    # after container recreates
    resolver 127.0.0.11 valid=30s ipv6=off;

    # Allow large file uploads (up to 100MB)
    client_max_body_size 100m;

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

    # API proxy — variable forces nginx to re-resolve on each request
    location /api/ {
        set $backend http://chrysopedia-api:8000;
        proxy_pass $backend;
        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_read_timeout 300s;
        proxy_send_timeout 300s;
    }

    location /health {
        set $backend http://chrysopedia-api:8000;
        proxy_pass $backend;
    }
}
