|
@@ -10,10 +10,11 @@
|
|
|
*
|
|
*
|
|
|
* 优先使用 NEXT_PUBLIC_API_BASE_URL 覆盖(CI / 临时调试)。
|
|
* 优先使用 NEXT_PUBLIC_API_BASE_URL 覆盖(CI / 临时调试)。
|
|
|
*
|
|
*
|
|
|
- * 动态域名:将对应环境的地址设为字面量 `__ORIGIN__`(不区分大小写)时,
|
|
|
|
|
- * - 浏览器:使用 `window.location.origin`(与当前访问域名一致)
|
|
|
|
|
- * - 服务端(RSC / Route Handler 等发 axios):需配置 `NEXT_PUBLIC_SITE_URL`(完整站点根,如 https://app.example.com);
|
|
|
|
|
- * 部署在 Vercel 时可回退使用 `VERCEL_URL`(自动加 https://)
|
|
|
|
|
|
|
+ * 动态域名:将对应环境的地址设为字面量 `__ORIGIN__`(不区分大小写)时,主接口 base 为「当前站点 + /api-backend」,
|
|
|
|
|
+ * 由 Next `rewrites` 转到 `API_PROXY_TARGET`(主业务端口,如 :8005),不要把端口写进公网 URL。
|
|
|
|
|
+ * - 浏览器:`/api-backend`(同源,端口随页面)
|
|
|
|
|
+ * - 服务端 axios:需 `NEXT_PUBLIC_SITE_URL`(如 https://app.example.com)拼成 `https://app.example.com/api-backend`;
|
|
|
|
|
+ * Vercel 可回退 `VERCEL_URL`。
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
const ORIGIN_PLACEHOLDER = "__origin__";
|
|
const ORIGIN_PLACEHOLDER = "__origin__";
|
|
@@ -31,15 +32,17 @@ function resolvePublicSiteOrigin(): string {
|
|
|
return "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** 将 `__ORIGIN__` 解析为当前站点 origin;非占位符则原样返回(已 trim)。 */
|
|
|
|
|
|
|
+/** 将 `__ORIGIN__` 解析为「当前站点下的 /api-backend」;非占位符则原样返回(已 trim)。 */
|
|
|
function resolveApiBaseUrlValue(raw: string | undefined): string {
|
|
function resolveApiBaseUrlValue(raw: string | undefined): string {
|
|
|
const s = raw?.trim() ?? "";
|
|
const s = raw?.trim() ?? "";
|
|
|
if (!s) return "";
|
|
if (!s) return "";
|
|
|
if (s.toLowerCase() === ORIGIN_PLACEHOLDER) {
|
|
if (s.toLowerCase() === ORIGIN_PLACEHOLDER) {
|
|
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
|
- return window.location.origin;
|
|
|
|
|
|
|
+ return `${window.location.origin}/api-backend`;
|
|
|
}
|
|
}
|
|
|
- return resolvePublicSiteOrigin();
|
|
|
|
|
|
|
+ const origin = resolvePublicSiteOrigin();
|
|
|
|
|
+ if (origin) return `${origin}/api-backend`;
|
|
|
|
|
+ return "/api-backend";
|
|
|
}
|
|
}
|
|
|
return s;
|
|
return s;
|
|
|
}
|
|
}
|
|
@@ -70,15 +73,24 @@ export function getRemittanceApiBaseUrl(): string {
|
|
|
const explicit = process.env.NEXT_PUBLIC_REMITTANCE_API_BASE_URL?.trim();
|
|
const explicit = process.env.NEXT_PUBLIC_REMITTANCE_API_BASE_URL?.trim();
|
|
|
if (explicit) return explicit.replace(/\/$/, "");
|
|
if (explicit) return explicit.replace(/\/$/, "");
|
|
|
|
|
|
|
|
- const base = getApiBaseUrl();
|
|
|
|
|
|
|
+ const base = getApiBaseUrl().replace(/\/$/, "");
|
|
|
if (!base) return "";
|
|
if (!base) return "";
|
|
|
|
|
|
|
|
|
|
+ // 与主接口同源反写:/api-backend → /api-backend-remittance(Next 转发到 API_PROXY_TARGET_REMITTANCE,如 :8504)
|
|
|
|
|
+ if (base === "/api-backend" || base.endsWith("/api-backend")) {
|
|
|
|
|
+ return base.replace(/\/api-backend$/, "/api-backend-remittance");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
const url = new URL(base);
|
|
const url = new URL(base);
|
|
|
- url.port = "8504";
|
|
|
|
|
- return url.toString().replace(/\/$/, "");
|
|
|
|
|
|
|
+ // 历史:直连主后端且带非默认端口(如 :8005),用换端口表示汇款服务(不推荐与 __ORIGIN__ 同源反写混用)
|
|
|
|
|
+ if (url.port && url.port !== "443" && url.port !== "80") {
|
|
|
|
|
+ url.port = "8504";
|
|
|
|
|
+ return url.toString().replace(/\/$/, "");
|
|
|
|
|
+ }
|
|
|
|
|
+ return `${url.origin}/api-backend-remittance`.replace(/\/$/, "");
|
|
|
} catch {
|
|
} catch {
|
|
|
- return base.replace(/\/$/, "");
|
|
|
|
|
|
|
+ return "/api-backend-remittance";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|