# Standalone Nginx server block — serves the built dashboard (frontend) AND reverse-proxies
# the Flask backend, all in this one file. Nginx equivalent of apache-vhost.conf.
#
# ============================ EDIT THESE BEFORE DEPLOYING ============================
# Path to the built dashboard, i.e. the contents of backend/static (index.html + assets/).
# Update this any time the deploy path changes.
#   root_path:      /CHANGE/ME/path/to/dashboard/static
#
#   server_name:    pandabugsreporting.com
#   backend_origin: http://97.74.90.109:8000   (matches docker-compose.yml's "8000:8000")
#
# TLS certificate files (e.g. certbot puts these under /etc/letsencrypt/live/<domain>/,
# cPanel AutoSSL under /etc/pki/tls/certs/<domain>.crt + /etc/pki/tls/private/<domain>.key).
#   ssl_cert:       /CHANGE/ME/fullchain.pem
#   ssl_key:        /CHANGE/ME/privkey.pem
# =======================================================================================

server {
    listen 80;
    listen [::]:80;
    server_name pandabugsreporting.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name pandabugsreporting.com;

    ssl_certificate     /CHANGE/ME/fullchain.pem;
    ssl_certificate_key /CHANGE/ME/privkey.pem;

    root /CHANGE/ME/path/to/dashboard/static;
    index index.html;

    # /api/* -> the dockerized Flask backend. Matched first so it's never shadowed by the
    # SPA fallback location below.
    location /api {
        proxy_pass http://97.74.90.109:8000/api;
        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;
    }

    # SPA fallback: any non-file path falls through to index.html so React Router's
    # client-side routes (e.g. /projects/1/issues/2) work on a hard refresh.
    location / {
        try_files $uri $uri/ /index.html;
    }
}
