's'
This commit is contained in:
@@ -49,7 +49,6 @@ function resolvePayApiUrl(request: NextRequest): string {
|
|||||||
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||||
return (
|
return (
|
||||||
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) ||
|
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) ||
|
||||||
process.env.PAYMENT_API_URL ||
|
|
||||||
payConfig.apiUrl
|
payConfig.apiUrl
|
||||||
).replace(/\/$/, "");
|
).replace(/\/$/, "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,7 @@ function resolvePayApiUrl(request: NextRequest): string {
|
|||||||
const config = getPaymentConfig();
|
const config = getPaymentConfig();
|
||||||
const hostHeader =
|
const hostHeader =
|
||||||
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||||
return (
|
return (getApiUrlFromRequest(hostHeader) || config.apiUrl).replace(/\/$/, "");
|
||||||
getApiUrlFromRequest(hostHeader) ||
|
|
||||||
process.env.PAYMENT_API_URL ||
|
|
||||||
config.apiUrl
|
|
||||||
).replace(/\/$/, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPayOrderCookie(response: NextResponse, orderId: string) {
|
function setPayOrderCookie(response: NextResponse, orderId: string) {
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ function resolvePayApiUrl(request: NextRequest): string {
|
|||||||
const config = getPaymentConfig();
|
const config = getPaymentConfig();
|
||||||
const hostHeader =
|
const hostHeader =
|
||||||
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||||
return (
|
return (getApiUrlFromRequest(hostHeader) || config.apiUrl).replace(/\/$/, "");
|
||||||
getApiUrlFromRequest(hostHeader) ||
|
|
||||||
process.env.PAYMENT_API_URL ||
|
|
||||||
config.apiUrl
|
|
||||||
).replace(/\/$/, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
|
|||||||
@@ -16,11 +16,20 @@ const isDev = process.env.NODE_ENV === "development";
|
|||||||
export const ROOT_DOMAIN =
|
export const ROOT_DOMAIN =
|
||||||
process.env.ROOT_DOMAIN || process.env.NEXT_PUBLIC_ROOT_DOMAIN || "hackrobot.cn";
|
process.env.ROOT_DOMAIN || process.env.NEXT_PUBLIC_ROOT_DOMAIN || "hackrobot.cn";
|
||||||
|
|
||||||
/** 支付 API 默认地址(本地可用 PAYMENT_API_URL 覆盖,如 http://192.168.41.222:8007) */
|
/** 支付 API 默认地址。生产环境固定为 api.${ROOT_DOMAIN},避免 .env 中 127.0.0.1 导致支付失败 */
|
||||||
export const DEFAULT_PAYMENT_API_URL = isDev
|
export const DEFAULT_PAYMENT_API_URL = isDev
|
||||||
? "http://127.0.0.1:8007"
|
? "http://127.0.0.1:8007"
|
||||||
: `https://api.${ROOT_DOMAIN}`;
|
: `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;
|
||||||
|
}
|
||||||
|
|
||||||
/** PocketBase 默认地址 */
|
/** PocketBase 默认地址 */
|
||||||
export const DEFAULT_POCKETBASE_URL = `https://pocketbase.${ROOT_DOMAIN}`;
|
export const DEFAULT_POCKETBASE_URL = `https://pocketbase.${ROOT_DOMAIN}`;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { getThemeConfig } from "./site.config";
|
import { getThemeConfig } from "./site.config";
|
||||||
import {
|
import {
|
||||||
DEFAULT_PAYMENT_API_URL,
|
DEFAULT_PAYMENT_API_URL,
|
||||||
|
resolvePaymentApiUrl,
|
||||||
DEFAULT_POCKETBASE_URL,
|
DEFAULT_POCKETBASE_URL,
|
||||||
DEFAULT_MINIO_HOST,
|
DEFAULT_MINIO_HOST,
|
||||||
} from "./domain.config";
|
} from "./domain.config";
|
||||||
@@ -74,7 +75,7 @@ export const VIP_MASTER_SITE_ID = "vip";
|
|||||||
|
|
||||||
export function getApiUrlFromRequest(hostHeader: string | null): string | null {
|
export function getApiUrlFromRequest(hostHeader: string | null): string | null {
|
||||||
if (!hostHeader) return null;
|
if (!hostHeader) return null;
|
||||||
if (!isDev) return process.env.PAYMENT_API_URL || DEFAULT_PAYMENT_API_URL;
|
if (!isDev) return resolvePaymentApiUrl();
|
||||||
const hostname = hostHeader.split(":")[0];
|
const hostname = hostHeader.split(":")[0];
|
||||||
return `http://${hostname}:${PAYJSAPI_PORT}`;
|
return `http://${hostname}:${PAYJSAPI_PORT}`;
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,7 @@ export function getPocketBaseConfig(themeOverride?: { joinCollection?: string })
|
|||||||
export function getPaymentConfig(themeOverride?: { amount?: number; type?: string }): PaymentConfig {
|
export function getPaymentConfig(themeOverride?: { amount?: number; type?: string }): PaymentConfig {
|
||||||
const base = {
|
const base = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
apiUrl: process.env.PAYMENT_API_URL || DEFAULT_PAYMENT_API_URL,
|
apiUrl: resolvePaymentApiUrl(),
|
||||||
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
|
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
|
||||||
defaultAmount: Number(process.env.PAYMENT_DEFAULT_AMOUNT) || 8800,
|
defaultAmount: Number(process.env.PAYMENT_DEFAULT_AMOUNT) || 8800,
|
||||||
defaultType: process.env.PAYMENT_DEFAULT_TYPE || "meetup",
|
defaultType: process.env.PAYMENT_DEFAULT_TYPE || "meetup",
|
||||||
|
|||||||
Reference in New Issue
Block a user