s''
This commit is contained in:
@@ -39,7 +39,6 @@ async function verifyOrderPaid(request: NextRequest, orderId: string): Promise<b
|
|||||||
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||||
const apiUrl = (
|
const apiUrl = (
|
||||||
getApiUrlFromRequest(hostHeader) ||
|
getApiUrlFromRequest(hostHeader) ||
|
||||||
process.env.PAYMENT_API_URL ||
|
|
||||||
config.apiUrl
|
config.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) {
|
||||||
|
|||||||
@@ -8,11 +8,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 覆盖) */
|
/** 支付 API 默认地址。生产环境固定为 api 域名,避免 .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;
|
||||||
|
}
|
||||||
|
|
||||||
export const DEFAULT_POCKETBASE_URL = `https://pocketbase.${ROOT_DOMAIN}`;
|
export const DEFAULT_POCKETBASE_URL = `https://pocketbase.${ROOT_DOMAIN}`;
|
||||||
|
|
||||||
export const DEFAULT_MINIO_HOST = `minioweb.${ROOT_DOMAIN}`;
|
export const DEFAULT_MINIO_HOST = `minioweb.${ROOT_DOMAIN}`;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
DEFAULT_PAYMENT_API_URL,
|
DEFAULT_PAYMENT_API_URL,
|
||||||
DEFAULT_POCKETBASE_URL,
|
DEFAULT_POCKETBASE_URL,
|
||||||
DEFAULT_MINIO_HOST,
|
DEFAULT_MINIO_HOST,
|
||||||
|
resolvePaymentApiUrl,
|
||||||
} from "./domain.config";
|
} from "./domain.config";
|
||||||
|
|
||||||
export interface PocketBaseConfig {
|
export interface PocketBaseConfig {
|
||||||
@@ -49,7 +50,7 @@ export const MEETUP_JOIN_AMOUNT = 8800;
|
|||||||
|
|
||||||
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}`;
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ export function getPocketBaseConfig(): PocketBaseConfig {
|
|||||||
export function getPaymentConfig(): PaymentConfig {
|
export function getPaymentConfig(): PaymentConfig {
|
||||||
return {
|
return {
|
||||||
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