diff --git a/api/relay.ts b/api/relay.ts index aa42fdd..1a47f58 100644 --- a/api/relay.ts +++ b/api/relay.ts @@ -362,10 +362,16 @@ export default { async fetch(req: Request): Promise { const url = new URL(req.url); - // Static routes + // Static routes — show index only when no relay target is requested if (url.pathname === "/health") return handleHealth(); if (url.pathname === "/docs") return handleDocs(); - if (url.pathname === "/" && req.method === "GET") return handleIndex(); + if ( + url.pathname === "/" && + req.method === "GET" && + !req.headers.get("x-relay-target") + ) { + return handleIndex(); + } // WebSocket upgrade — not supported in Vercel Functions if ( diff --git a/src/index.ts b/src/index.ts index 61c5ed7..7d69782 100644 --- a/src/index.ts +++ b/src/index.ts @@ -433,7 +433,8 @@ const server: Server = Bun.serve({ // Static routes if (url.pathname === "/health") return handleHealth(); if (url.pathname === "/docs") return handleDocs(); - if (url.pathname === "/" && req.method === "GET") return handleIndex(); + if (url.pathname === "/" && req.method === "GET" && !req.headers.get("x-relay-target")) + return handleIndex(); // WebSocket upgrade check — if the target is ws:// or wss://, // attempt to upgrade and relay. This must happen before the diff --git a/src/worker.ts b/src/worker.ts index 79cf4e7..e32c9aa 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -358,10 +358,16 @@ export default { async fetch(req: Request, env: Env): Promise { const url = new URL(req.url); - // Static routes + // Static routes — show index only when no relay target is requested if (url.pathname === "/health") return handleHealth(); if (url.pathname === "/docs") return handleDocs(); - if (url.pathname === "/" && req.method === "GET") return handleIndex(); + if ( + url.pathname === "/" && + req.method === "GET" && + !req.headers.get("x-relay-target") + ) { + return handleIndex(); + } // WebSocket upgrade — not fully supported in this handler if (