# nginx.conf - NOFX Frontend (optimized for SPA + API proxy)
# - Proper SPA fallback (no nested locations)
# - Static assets caching
# - API proxy to backend service name (compose: nofx)
# - Simple /health for container healthcheck

server {
    listen 80;
    server_name localhost;

    # Frontend root (compose copies build to this path)
    root /usr/share/nginx/html;
    index index.html;

    # Gzip compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/xml text/javascript application/javascript application/json image/svg+xml;

    # SPA fallback: route all non-file requests to index.html
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Static assets caching (immutable fingerprints)
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Proxy API requests to backend (service name: nofx)
    location /api/ {
        proxy_pass http://nofx:8080/api/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
    }

    # Health check endpoint (independent of backend)
    location /health {
        return 200 "OK\n";
        add_header Content-Type text/plain;
        access_log off;
    }
}