fix(Venom): 修复 API base 被 Vite 编译成静态资源查找导致请求 undefined 路径

Vite 会把 new URL(动态拼接串, import.meta.url) 编译为 Object.assign({})[key] 资源表查找,运行时取到 undefined(请求变成 .../venom/undefined/packages/);改为正则 + 字符串拼接自行推导同源 RemoteApi 基址
This commit is contained in:
TermiNexus committed 2026-10-07 17:39:12 +08:00
1 parent 89274ea2bd
commit 3e642ca119
1 file changed
+9 -9
+9 -9
View File
@@ -9,17 +9,17 @@
*/
const API_BASE = (() => {
const proxied = /\/API\/Subscription\/RemoteAsset\/([^/]+)\//.exec(import.meta.url)
// 主服务缓存代理模式:模块 URL 形如
// https://gerp.gvsds.com/API/Subscription/RemoteAsset/<GroupUUID>/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 {