From 3230156ada9f009d08e8902b61ae361b70316e9f Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Wed, 3 Dec 2025 21:09:20 -0800 Subject: [PATCH] Fix WebSocket upgrade by moving / route to fetch handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Routes in Bun.serve() take precedence over WebSocket upgrade checks. Move the root path handler to the fetch() function so WebSocket upgrade requests are processed first. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/aggregator/index.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/aggregator/index.ts b/src/aggregator/index.ts index b53357c..bf07141 100644 --- a/src/aggregator/index.ts +++ b/src/aggregator/index.ts @@ -91,16 +91,7 @@ export class BacklogAggregator { port: this.config.port, development: process.env.NODE_ENV === "development", routes: { - "/": async () => { - const htmlPath = pathJoin(__dirname, "web", "index.html"); - const htmlFile = Bun.file(htmlPath); - return new Response(htmlFile, { headers: { "Content-Type": "text/html" } }); - }, - "/app.tsx": async () => { - const tsxPath = pathJoin(__dirname, "web", "app.tsx"); - const tsxFile = Bun.file(tsxPath); - return new Response(tsxFile, { headers: { "Content-Type": "application/javascript" } }); - }, + // NOTE: "/" route is handled in fetch() to allow WebSocket upgrade "/api/projects": { GET: async () => this.handleGetProjects(), }, @@ -138,6 +129,13 @@ export class BacklogAggregator { }); } + // Serve the HTML app for root path + if (url.pathname === "/" || url.pathname === "") { + const htmlPath = pathJoin(__dirname, "web", "index.html"); + const htmlFile = Bun.file(htmlPath); + return new Response(htmlFile, { headers: { "Content-Type": "text/html" } }); + } + return new Response("Not Found", { status: 404 }); }, websocket: {