Files
2026-03-15 11:19:52 -05:00

24 lines
876 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 域名与 payjsapi 地址配置
* 生产环境必须设置 PAYMENT_API_URL 或 ROOT_DOMAIN否则无法连接 payjsapi
*/
const isDev = process.env.NODE_ENV === "development";
export const ROOT_DOMAIN =
process.env.ROOT_DOMAIN || process.env.NEXT_PUBLIC_ROOT_DOMAIN || "hackrobot.cn";
/** 支付 API 默认地址。生产环境使用 api 子域,避免 127.0.0.1 导致连接失败 */
export const DEFAULT_PAYMENT_API_URL = isDev
? "http://127.0.0.1:8007"
: `https://api.${ROOT_DOMAIN}`;
/** 若 PAYMENT_API_URL 指向 localhost生产环境自动使用 api 子域 */
export function resolvePaymentApiUrl(): string {
const url = process.env.PAYMENT_API_URL || DEFAULT_PAYMENT_API_URL;
if (!isDev && /^(https?:\/\/)?(127\.0\.0\.1|localhost)(:\d+)?(\/|$)/i.test(url)) {
return `https://api.${ROOT_DOMAIN}`;
}
return url.replace(/\/$/, "");
}