# Example nginx site for kastia.net → HollowCade on 127.0.0.1:3000
#
# On the server:
#   sudo cp deploy/nginx-kastia.net.conf /etc/nginx/sites-available/kastia.net
#   # OR merge the /roms/ and /covers/ location blocks into your live site
#   sudo nginx -t && sudo systemctl reload nginx
#
# Find what owns port 80:  sudo ss -tlnp | grep ':80'

server {
    listen 80;
    listen [::]:80;
    server_name kastia.net www.kastia.net;

    # Uncomment after certbot, or let certbot rewrite this file:
    # listen 443 ssl http2;
    # listen [::]:443 ssl http2;
    # ssl_certificate     /etc/letsencrypt/live/kastia.net/fullchain.pem;
    # ssl_certificate_key /etc/letsencrypt/live/kastia.net/privkey.pem;
    # include /etc/letsencrypt/options-ssl-nginx.conf;

    client_max_body_size 512M;

    proxy_request_buffering off;
    proxy_read_timeout 3600;
    proxy_send_timeout 3600;

    # Serve ROMs/covers from disk — avoids Next.js permission / body issues
    # Adjust alias if your clone is not /var/www/html
    location /roms/ {
        alias /var/www/html/public/roms/;
        add_header Cross-Origin-Resource-Policy cross-origin always;
        add_header Cache-Control "public, max-age=3600";
        types { }
        default_type application/octet-stream;
    }

    location /covers/ {
        alias /var/www/html/public/covers/;
        add_header Cache-Control "public, max-age=86400";
    }

    location / {
        proxy_pass http://127.0.0.1:3000;
        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;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 3600;
    }
}
