From 98962da74f5766ab64f6e8f0f0e007ae117c2c0d Mon Sep 17 00:00:00 2001 From: Yogesh Tejwani Date: Fri, 19 Jun 2026 13:16:33 +0530 Subject: [PATCH] fix(ui): proxy WebSocket signaling upgrade so local web calls work (#425) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.34.0 replaced the next.config `/api/* -> BACKEND_URL` rewrite with the Route Handler `api/v1/[...path]/route.ts`. Route Handlers proxy HTTP fine (so `/api/v1/*` still 200s) but cannot upgrade WebSocket connections. The removed *rewrite* used to carry the upgrade, so without it the signaling socket (`/api/v1/ws/signaling/...`) has no proxy path and every local web call dies before WebRTC negotiation — the symptom reported in #425. nginx would proxy the upgrade but only runs in the `remote` compose profile, so local OSS deployments have nothing to carry it. Re-add a `beforeFiles` rewrite scoped to `/api/v1/ws/:path*` so the upgrade is proxied to the backend *before* the `[...path]` Route Handler can swallow it. HTTP `/api/v1/*` is untouched and still flows through the Route Handler (auth/cookie handling intact). Verified on a 1.34.0-derived source build: signaling WS now reports `[accepted]` / `connection open` server-side and `WebSocket connected` + `ICE connection state: connected` client-side; WebRTC negotiates end-to-end. Co-Authored-By: Claude Opus 4.8 (1M context) --- ui/next.config.ts | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/ui/next.config.ts b/ui/next.config.ts index 98242c20..48708c72 100644 --- a/ui/next.config.ts +++ b/ui/next.config.ts @@ -8,20 +8,35 @@ const nextConfig: NextConfig = { serverSourceMaps: true, }, async rewrites() { - return [ - { - source: "/ingest/static/:path*", - destination: "https://us-assets.i.posthog.com/static/:path*", - }, - { - source: "/ingest/:path*", - destination: "https://us.i.posthog.com/:path*", - }, - { - source: "/ingest/decide", - destination: "https://us.i.posthog.com/decide", - }, - ]; + return { + // beforeFiles runs before Next.js route handlers, so the WebSocket + // signaling path is proxied straight to the backend instead of being + // swallowed by api/v1/[...path]/route.ts — a Route Handler that proxies + // HTTP fine but CANNOT upgrade WebSocket connections. The pre-1.34.0 + // /api proxy *rewrite* used to carry this upgrade; removing it broke all + // local web calls (dograh #425). Scoped to /ws/ so HTTP /api/v1 still + // flows through the route handler (auth/cookie handling intact). + beforeFiles: [ + { + source: "/api/v1/ws/:path*", + destination: `${process.env.BACKEND_URL || 'http://localhost:8000'}/api/v1/ws/:path*`, + }, + ], + afterFiles: [ + { + source: "/ingest/static/:path*", + destination: "https://us-assets.i.posthog.com/static/:path*", + }, + { + source: "/ingest/:path*", + destination: "https://us.i.posthog.com/:path*", + }, + { + source: "/ingest/decide", + destination: "https://us.i.posthog.com/decide", + }, + ], + }; }, // This is required to support PostHog trailing slash API requests skipTrailingSlashRedirect: true,