Skip to content

Commit 3096f09

Browse files
committed
Rewrite docs.redpanda.com URLs to current origin to fix CORS and history API errors
1 parent 96fdba0 commit 3096f09

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

netlify/edge-functions/proxy-api-docs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.56/deno-dom-wasm.ts
33
export default async (request, context) => {
44
const url = new URL(request.url);
55
const originalOrigin = "https://docs.redpanda.com";
6+
const currentOrigin = url.origin;
67

78
// Redirects from old API paths to new ones
89
const redirects = {
@@ -82,10 +83,13 @@ export default async (request, context) => {
8283
fetchWidget(`${originalOrigin}/assets/widgets/footer.html`, "footer"),
8384
]);
8485

85-
const document = new DOMParser().parseFromString(originalHtml, "text/html");
86+
// Rewrite absolute docs.redpanda.com URLs to use current origin to avoid CORS and history API issues
87+
const rewrittenHtml = originalHtml.replace(/https:\/\/docs\.redpanda\.com/g, currentOrigin);
88+
89+
const document = new DOMParser().parseFromString(rewrittenHtml, "text/html");
8690
if (!document) {
8791
console.error("❌ Failed to parse Bump.sh HTML.");
88-
return new Response(originalHtml, {
92+
return new Response(rewrittenHtml, {
8993
status: 200,
9094
headers: { "content-type": "text/html; charset=utf-8" },
9195
});

0 commit comments

Comments
 (0)