From 3e642ca1194dd04e5f844715645ef30828abc431 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 7 Oct 2026 17:39:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(Venom):=20=E4=BF=AE=E5=A4=8D=20API=20base?= =?UTF-8?q?=20=E8=A2=AB=20Vite=20=E7=BC=96=E8=AF=91=E6=88=90=E9=9D=99?= =?UTF-8?q?=E6=80=81=E8=B5=84=E6=BA=90=E6=9F=A5=E6=89=BE=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=20undefined=20=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vite 会把 new URL(动态拼接串, import.meta.url) 编译为 Object.assign({})[key] 资源表查找,运行时取到 undefined(请求变成 .../venom/undefined/packages/);改为正则 + 字符串拼接自行推导同源 RemoteApi 基址 --- GVSDServiceServer/venom_ui/src/api.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/GVSDServiceServer/venom_ui/src/api.ts b/GVSDServiceServer/venom_ui/src/api.ts index 17a394f4..9888640f 100644 --- a/GVSDServiceServer/venom_ui/src/api.ts +++ b/GVSDServiceServer/venom_ui/src/api.ts @@ -9,17 +9,17 @@ */ const API_BASE = (() => { - const proxied = /\/API\/Subscription\/RemoteAsset\/([^/]+)\//.exec(import.meta.url) + // 主服务缓存代理模式:模块 URL 形如 + // https://gerp.gvsds.com/API/Subscription/RemoteAsset//venom/remote-entry.js + // + // 注意:**不能**写成 `new URL(动态拼接串, import.meta.url)`——Vite 会把「动态首参」 + // 的 new URL 编译成静态资源表查找(`Object.assign({})[key]`),运行时取到 undefined, + // 表现为请求 `.../venom/undefined/packages/`。故这里用字符串替换自行拼接。 + const proxied = /^(.*\/API\/Subscription\/)RemoteAsset\/([^/]+)\//.exec(import.meta.url) if (proxied) { - try { - return new URL( - `/API/Subscription/RemoteApi/${proxied[1]}/api/venom`, - import.meta.url, - ).toString() - } catch { - /* 落到直连分支 */ - } + return `${proxied[1]}RemoteApi/${proxied[2]}/api/venom` } + // 未启用代理(本地直连子服务器):按当前模块地址推断同源 /api/venom try { return new URL('/api/venom', import.meta.url).toString() } catch {