fix
All checks were successful
Build and Deploy Front / deploy (push) Successful in 5m25s

This commit is contained in:
xiaolipro 2026-09-22 16:42:16 +08:00
parent 7c29005cb6
commit e5c2200804
2 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,5 @@
# k3s / Kaniko:静态 SPA(方案 A)。API 由浏览器按站点域名直连 # k3s / Kaniko:静态 SPA(方案 A)。API 由浏览器按站点域名直连
# app.test.ideship.com → api.test.ideship.com;其余 → api.ideship.com # test.ideship.com → api.test.ideship.com;其余 → api.ideship.com
# 镜像内 nginx 不做反代;也可用构建期 VITE_API_ORIGIN / VITE_API_ADMIN_URL 覆盖 # 镜像内 nginx 不做反代;也可用构建期 VITE_API_ORIGIN / VITE_API_ADMIN_URL 覆盖
FROM docker.m.daocloud.io/library/node:20-alpine AS build FROM docker.m.daocloud.io/library/node:20-alpine AS build
WORKDIR /app WORKDIR /app

View File

@ -1,7 +1,7 @@
/** /**
* 方案 A:浏览器直连 API 网关 PATHBASE;开发仍走 Vite 代理旧路径。 * 方案 A:浏览器直连 API 网关 PATHBASE;开发仍走 Vite 代理旧路径。
* - prod:https://api.ideship.com * - prod:https://api.ideship.com
* - test(app.test.ideship.com):https://api.test.ideship.com * - test(test.ideship.com):https://api.test.ideship.com
* - 可用 VITE_API_ORIGIN 覆盖 * - 可用 VITE_API_ORIGIN 覆盖
*/ */
@ -21,16 +21,21 @@ const SPA_API_PREFIXES = [
const DEFAULT_PROD_API = 'https://api.ideship.com' const DEFAULT_PROD_API = 'https://api.ideship.com'
const DEFAULT_TEST_API = 'https://api.test.ideship.com' const DEFAULT_TEST_API = 'https://api.test.ideship.com'
function isTestFrontHost(hostname: string): boolean {
return (
hostname === 'test.ideship.com' ||
hostname === 'app.test.ideship.com' || // 旧域名兼容
hostname.endsWith('.test.ideship.com')
)
}
/** 生产/测试 API 根(无尾斜杠) */ /** 生产/测试 API 根(无尾斜杠) */
export function prodApiOrigin(): string { export function prodApiOrigin(): string {
const override = (import.meta.env.VITE_API_ORIGIN as string | undefined)?.trim() const override = (import.meta.env.VITE_API_ORIGIN as string | undefined)?.trim()
if (override) return override.replace(/\/$/, '') if (override) return override.replace(/\/$/, '')
if (typeof window !== 'undefined') { if (typeof window !== 'undefined' && isTestFrontHost(window.location.hostname)) {
const h = window.location.hostname
if (h === 'app.test.ideship.com' || h.endsWith('.test.ideship.com')) {
return DEFAULT_TEST_API return DEFAULT_TEST_API
} }
}
return DEFAULT_PROD_API return DEFAULT_PROD_API
} }