# SDP nginx for 186 — mount the dashboard under /sandbox/credit-card
# and proxy /api/ + /ws/ to the control plane on 127.0.0.1:3452.
#
# Splice the four location blocks into the existing
# /etc/nginx/sites-available/default server { } on 186. Order doesn't
# matter for these specific prefixes (they're disjoint), but
# longest-prefix-first is the convention.
#
# Verify with `sudo nginx -t` then `sudo systemctl reload nginx`.

# Static asset chunks (hashed filenames, safe to cache forever).
location /sandbox/credit-card/_next/static/ {
    alias /home/administrator/SDP/dashboard/_next/static/;
    expires 1y;
    add_header Cache-Control "public, immutable";
}

# API: control plane on 127.0.0.1:3452. The proxy_pass has no path
# component, so the original /api/... URI is forwarded unchanged.
location /sandbox/credit-card/api/ {
    proxy_pass http://127.0.0.1:3452;
    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_read_timeout 3600s;
}

# WebSocket: deployment log subscriptions + agent WS.
location /sandbox/credit-card/ws/ {
    proxy_pass http://127.0.0.1:3452;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_read_timeout 3600s;
}

# Everything else under /sandbox/credit-card: serve the static
# dashboard. Client-side routes (e.g. /sandbox/credit-card/dashboard/sandboxes/abc)
# fall through to /index.html, which Next.js hydrates and the React
# Router takes over.
location /sandbox/credit-card {
    alias /home/administrator/SDP/dashboard/;
    index index.html;
    try_files $uri $uri/ $uri.html /index.html;
}
