# nginx.conf - Extracted Nginx configuration for NOFX Frontend
# This configuration merges enhancements from provided variants: improved gzip, static asset caching, adjusted API proxy (preserving /api/ path), extended timeouts, and a static health response for frontend independence.

server {
    listen 80;
    server_name localhost;

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

    # Gzip compression (enhanced)
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json;

    # index.html — never cache (so new deploys take effect immediately)
    location = /index.html {
        add_header Cache-Control "no-cache, no-store, must-revalidate";
        add_header Pragma "no-cache";
        add_header Expires 0;
    }

    # Frontend routes (SPA) with static asset caching
    location / {
        try_files $uri $uri/ /index.html;

        # Cache hashed static assets (js/css have content hashes in filenames)
        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 (preserves /api/ path, with timeouts)
    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_cache_bypass $http_upgrade;
        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;

        # Increase timeout for long-running API calls
        proxy_connect_timeout 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
    }

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