Files
PolyWeather/frontend/lib/payment-host.ts
T
2569718930@qq.com 617d3c910e 支付域名识别更新:Vercel → polyweather.top
payment-host.ts 新增 polyweather.top。site-url.ts/wallet.ts/usePaymentFlow/AccountCenter 硬编码域名替换。PRODUCTION_SITE_URL 改为 https://polyweather.top
2026-05-26 00:33:02 +08:00

45 lines
1.1 KiB
TypeScript

const DEFAULT_ALLOWED_PAYMENT_HOSTS = [
"polyweather-pro.vercel.app",
"polyweather.top",
"localhost",
"127.0.0.1",
];
function normalizeHost(raw: string | undefined | null): string {
return String(raw || "")
.trim()
.toLowerCase()
.replace(/^https?:\/\//, "")
.replace(/\/.*$/, "")
.replace(/:\d+$/, "");
}
export function getAllowedPaymentHosts(): string[] {
const configured = String(
process.env.NEXT_PUBLIC_PAYMENT_ALLOWED_HOSTS ||
process.env.POLYWEATHER_PAYMENT_ALLOWED_HOSTS ||
"",
)
.split(",")
.map((item) => normalizeHost(item))
.filter(Boolean);
if (!configured.length) {
return DEFAULT_ALLOWED_PAYMENT_HOSTS;
}
return Array.from(new Set([...configured, "localhost", "127.0.0.1"]));
}
export function isPaymentHostAllowed(hostname: string | undefined | null): boolean {
const normalized = normalizeHost(hostname);
if (!normalized) return false;
return getAllowedPaymentHosts().includes(normalized);
}
export function getCurrentPaymentHost(): string {
if (typeof window === "undefined") return "";
return normalizeHost(window.location.hostname || window.location.host);
}