Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/"))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure, we might need to remove the /docs prefix here, as we are behind the proxy:

Suggested change
response = await fetch(new URL("/docs/404.html", "https://docs.bomb.sh/"))
response = await fetch(new URL("/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<Env>;