server {
    # Port 8080 for unprivileged nginx (non-root)
    listen 8080;
    server_name _;

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

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    # Allow larger file uploads (for medication images)
    client_max_body_size 10M;

    location / {
        try_files $uri /index.html;
    }

    location /api/ {
        proxy_pass http://medassist-ng-backend:3000/;
        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;
        
        # Pass cookies through
        proxy_pass_header Set-Cookie;
        proxy_cookie_path / /;
        
        # Timeout for uploads
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }
}
