Files
PolyWeather/frontend/lib/payment-host.ts
2569718930@qq.com 88b80d66e8 全局替换旧域名 polyweather-pro.vercel.app → polyweather.top
- payment-host: 移除 vercel 域名,加 www.polyweather.top
- CORS: 移除 vercel,加 www
- bot: 绑定链接 + 市场概览提示
- weather_sources: User-Agent
2026-05-26 19:53:47 +08:00

45 lines
1.1 KiB
TypeScript

const DEFAULT_ALLOWED_PAYMENT_HOSTS = [
"polyweather.top",
"www.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);
}