From 70fed25da5d5e58754fed6ba4a4c759ace173b61 Mon Sep 17 00:00:00 2001 From: Felix Schneider <99918022+trueberryless@users.noreply.github.com> Date: Sat, 6 Jun 2026 19:26:15 +0200 Subject: [PATCH] fix: router logic 404 special case --- router/src/index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/router/src/index.ts b/router/src/index.ts index 1703f08..fa9f22c 100644 --- a/router/src/index.ts +++ b/router/src/index.ts @@ -5,19 +5,28 @@ export default { const url = new URL(request.url); if (url.pathname.startsWith("/docs")) { - const response = await fetch(new URL(url.pathname, "https://docs.bomb.sh/")); + let response = await fetch(new URL(url.pathname, "https://docs.bomb.sh/")); + + // Special case for Starlight's 404 page + let status = response.status; + if (status === 404) + response = await fetch(new URL("/docs/404.html", "https://docs.bomb.sh/")) + const headers = new Headers(response.headers); headers.set("Cross-Origin-Embedder-Policy", "require-corp"); headers.set("Cross-Origin-Opener-Policy", "same-origin"); headers.set("Cross-Origin-Resource-Policy", "cross-origin"); - headers.set("Referrer-Policy", "strict-origin-when-cross-origin"); + headers.set("Referrer-Policy", "strict-origin-when-cross-origin"); + + // If we got 404, return the HTML, but set status to 404 manually, + // because the response status would be 200 return new Response(response.body, { - status: response.status, - statusText: response.statusText, + status: status, + statusText: status === 404 ? "Not Found" : response.statusText, headers, }); } - return fetch(url); + return fetch(request); }, } satisfies ExportedHandler; \ No newline at end of file