# ─────────────────────────────────────────────────────────────────────────────
# AiMANAC — /ihp-ws WebSocket location block
# Place inside your `server { ... }` block, BEFORE any catch-all `location /`.
#
# The WebSocket upgrade headers are non-negotiable. The iOS client silently
# falls back to long-polling if the 101 handshake fails — you will not see
# an error, only mysterious latency.
#
# This block mirrors the exact directives running on the Everplay-Tech
# reference deploy (Hetzner host, nginx 1.24+) as of the CCW-1 cornerstone
# release (2026-05-10). Customer deploys should match these values rather
# than rely on an LLM-generated approximation.
# ─────────────────────────────────────────────────────────────────────────────

location /ihp-ws {
    proxy_pass         http://aimanac-server:3000;
    proxy_http_version 1.1;

    # Required for the WebSocket upgrade handshake.
    proxy_set_header   Upgrade           $http_upgrade;
    proxy_set_header   Connection        "upgrade";

    # Pass-through identity 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;

    # Critical: disable buffering on the WS route, otherwise frames stall.
    proxy_buffering    off;
    proxy_cache        off;

    # Long-lived sockets — give them room.
    proxy_read_timeout 86400;
    proxy_send_timeout 86400;
}
