# /etc/nginx/sites-available/forge
# Reverse proxy for Forge with SSE support

server {
    listen 80;
    server_name forge.example.com;

    # Redirect HTTP → HTTPS (uncomment after cert setup)
    # return 301 https://$host$request_uri;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;

        # SSE / WebSocket support
        proxy_set_header Connection '';
        proxy_buffering off;
        proxy_cache off;
        chunked_transfer_encoding off;

        # Timeouts — SSE needs long-lived connections
        proxy_read_timeout 86400s;
        proxy_send_timeout 86400s;

        # Standard proxy headers
        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;
    }
}

# HTTPS (uncomment after certbot setup)
# server {
#     listen 443 ssl http2;
#     server_name forge.example.com;
#     ssl_certificate     /etc/letsencrypt/live/forge.example.com/fullchain.pem;
#     ssl_certificate_key /etc/letsencrypt/live/forge.example.com/privkey.pem;
#     location / {
#         proxy_pass http://127.0.0.1:3000;
#         proxy_http_version 1.1;
#         proxy_set_header Connection '';
#         proxy_buffering off;
#         proxy_cache off;
#         chunked_transfer_encoding off;
#         proxy_read_timeout 86400s;
#         proxy_send_timeout 86400s;
#         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;
#     }
# }
