From c7d8a0e2bef456b44e8c41f71a9a3e2a0835cbb2 Mon Sep 17 00:00:00 2001 From: Gaubee Date: Wed, 21 Jan 2026 18:26:49 +0800 Subject: [PATCH] fix(wujie): simplify URL rewrite with direct new URL(url, placeholder) --- .../container/wujie-container.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/services/miniapp-runtime/container/wujie-container.ts b/src/services/miniapp-runtime/container/wujie-container.ts index 65efe2e42..582e01b5c 100644 --- a/src/services/miniapp-runtime/container/wujie-container.ts +++ b/src/services/miniapp-runtime/container/wujie-container.ts @@ -61,26 +61,17 @@ function rewriteHtmlAbsolutePaths(html: string, baseUrl: string): string { return doc.documentElement.outerHTML; } -const PLACEHOLDER_ORIGIN = 'https://placeholder.local'; +const PLACEHOLDER_ORIGIN = 'https://placeholder.local/'; function createAbsolutePathRewriter(baseUrl: string) { - const parsedUrl = new URL(baseUrl); - const targetBase = parsedUrl.origin + parsedUrl.pathname; + const targetBase = new URL(baseUrl).href; return { fetch: (input: RequestInfo | URL, init?: RequestInit) => { const req = new Request(input, init); - const parsedReqUrl = new URL(req.url); - - if (parsedReqUrl.origin === window.location.origin) { - 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); + const normalized = new URL(req.url, PLACEHOLDER_ORIGIN); + const rewrittenUrl = normalized.href.replace(PLACEHOLDER_ORIGIN, targetBase); + return window.fetch(rewrittenUrl, init); }, plugins: [ {