This commit is contained in:
eric
2026-03-13 06:16:36 -05:00
parent a42e9628ad
commit e673bc9b62
7 changed files with 11 additions and 14 deletions

View File

@@ -51,11 +51,20 @@ export function getApiUrlFromRequest(hostHeader: string | null): string {
return isDev ? `http://${hostname}:${PAYJSAPI_PORT}` : "https://api.hackrobot.cn";
}
export function getPaymentConfig(): PaymentConfig {
const apiUrl =
/** 生产环境若 PAYMENT_API_URL 指向 localhost则忽略并使用 api 域名 */
function resolvePaymentApiUrl(): string {
const url =
process.env.PAYMENT_API_URL ||
process.env.NEXT_PUBLIC_API_URL ||
(isDev ? `http://127.0.0.1:${PAYJSAPI_PORT}` : "https://api.hackrobot.cn");
if (!isDev && /^(https?:\/\/)?(127\.0\.0\.1|localhost)(:\d+)?(\/|$)/i.test(url)) {
return "https://api.hackrobot.cn";
}
return url;
}
export function getPaymentConfig(): PaymentConfig {
const apiUrl = resolvePaymentApiUrl();
return {
apiUrl,
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",