server {
    listen 80;
    server_name _;
    # Allow larger requests proxied to the Node backend (increase if needed)
    client_max_body_size 10M;

    root /app;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
        autoindex on;
    }

    location /publish/ {
        alias /app/publish/;
        autoindex on;
        add_header Access-Control-Allow-Origin "*";
        add_header Access-Control-Allow-Methods "GET, OPTIONS";
        add_header Access-Control-Allow-Headers "*";
    }

    location /api/ {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        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;
    }
}
