fix(ui): proxy WebSocket signaling upgrade so local web calls work (#425)

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) <noreply@anthropic.com>
This commit is contained in:
Yogesh Tejwani 2026-06-19 13:16:33 +05:30
parent 00a0de8a62
commit 98962da74f

View file

@ -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,