From 1d809b2c951f2692f0b25e013704229eebcad199 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sun, 16 Aug 2026 15:28:58 +0700 Subject: [PATCH] fix(proxy): route /trpc to backend so browser oRPC WebSocket opens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser connects oRPC over wss://…/trpc (partysocket). The gmw-proxy nginx only forwarded /api and /ws to the backend, so /trpc upgrades fell through to Next.js SSR and the socket never opened ("WebSocket is not open"). Add a /trpc location (WS upgrade headers) mirroring /ws. Backend already serves oRPC on /trpc (HTTP RPCHandler + WS ORPCWebSocketServer on :4001). Verified: ws://127.0.0.1:4001/trpc upgrade OPEN; SSR + server-side fetch RPCLink also use /trpc directly so only the browser path was broken. --- infra/nix/nginx.conf.template | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/infra/nix/nginx.conf.template b/infra/nix/nginx.conf.template index 19e1379..35f09e1 100644 --- a/infra/nix/nginx.conf.template +++ b/infra/nix/nginx.conf.template @@ -61,6 +61,25 @@ http { proxy_send_timeout 86400s; } + # ── Backend oRPC (structured data RPCs over WebSocket + HTTP POST) + # Browser reaches this via partysocket (wss://…/trpc); SSR/RSC uses + # the fetch RPCLink (POST /trpc). Same path, same backend handler: + # oRPC's RPCHandler (HTTP) + ORPCWebSocketServer (WS) on :4001. ── + location ^~ /trpc { + proxy_pass http://gmw_backend$uri$is_args$args; + proxy_http_version 1.1; + # Upgrade headers required for the WebSocket transport; harmless for POST. + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + 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_buffering off; + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; + } + # ── Next.js build assets — immutable, edge/shareable ─────────── location ^~ /_next/static/ { proxy_pass http://gmw_next$uri$is_args$args;