fix: relay requests to / with x-relay-target instead of showing index
When a GET request hits / with an x-relay-target header, it should relay the request — not display the index page. Fixed in all three entry points (src/index.ts, api/relay.ts, src/worker.ts). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
a67f9283e3
commit
3f96d8a6e7
+8
-2
@@ -362,10 +362,16 @@ export default {
|
|||||||
async fetch(req: Request): Promise<Response> {
|
async fetch(req: Request): Promise<Response> {
|
||||||
const url = new URL(req.url);
|
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 === "/health") return handleHealth();
|
||||||
if (url.pathname === "/docs") return handleDocs();
|
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
|
// WebSocket upgrade — not supported in Vercel Functions
|
||||||
if (
|
if (
|
||||||
|
|||||||
+2
-1
@@ -433,7 +433,8 @@ const server: Server<WSRelayData> = Bun.serve<WSRelayData>({
|
|||||||
// Static routes
|
// Static routes
|
||||||
if (url.pathname === "/health") return handleHealth();
|
if (url.pathname === "/health") return handleHealth();
|
||||||
if (url.pathname === "/docs") return handleDocs();
|
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://,
|
// WebSocket upgrade check — if the target is ws:// or wss://,
|
||||||
// attempt to upgrade and relay. This must happen before the
|
// attempt to upgrade and relay. This must happen before the
|
||||||
|
|||||||
+8
-2
@@ -358,10 +358,16 @@ export default {
|
|||||||
async fetch(req: Request, env: Env): Promise<Response> {
|
async fetch(req: Request, env: Env): Promise<Response> {
|
||||||
const url = new URL(req.url);
|
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 === "/health") return handleHealth();
|
||||||
if (url.pathname === "/docs") return handleDocs();
|
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
|
// WebSocket upgrade — not fully supported in this handler
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user