From 980c3671a344e9a520bcd394d23aaafea43b140b Mon Sep 17 00:00:00 2001 From: Gaubee Date: Wed, 21 Jan 2026 18:14:28 +0800 Subject: [PATCH] fix(wujie): use placeholder origin for URL rewrite to avoid path duplication --- .../miniapp-runtime/container/wujie-container.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/miniapp-runtime/container/wujie-container.ts b/src/services/miniapp-runtime/container/wujie-container.ts index 063055466..65efe2e42 100644 --- a/src/services/miniapp-runtime/container/wujie-container.ts +++ b/src/services/miniapp-runtime/container/wujie-container.ts @@ -61,9 +61,11 @@ function rewriteHtmlAbsolutePaths(html: string, baseUrl: string): string { return doc.documentElement.outerHTML; } +const PLACEHOLDER_ORIGIN = 'https://placeholder.local'; + function createAbsolutePathRewriter(baseUrl: string) { const parsedUrl = new URL(baseUrl); - const origin = parsedUrl.origin + parsedUrl.pathname.replace(/\/$/, ''); + const targetBase = parsedUrl.origin + parsedUrl.pathname; return { fetch: (input: RequestInfo | URL, init?: RequestInit) => { @@ -71,7 +73,11 @@ function createAbsolutePathRewriter(baseUrl: string) { const parsedReqUrl = new URL(req.url); if (parsedReqUrl.origin === window.location.origin) { - const rewrittenUrl = `${origin}${parsedReqUrl.pathname}${parsedReqUrl.search}${parsedReqUrl.hash}`; + const normalized = new URL( + parsedReqUrl.pathname + parsedReqUrl.search + parsedReqUrl.hash, + PLACEHOLDER_ORIGIN + '/', + ); + const rewrittenUrl = normalized.href.replace(PLACEHOLDER_ORIGIN + '/', targetBase); return window.fetch(rewrittenUrl, init); } return window.fetch(req);