mirror of
https://github.com/vercel/eve.git
synced 2026-09-20 05:35:39 +08:00
4751e69788
Signed-off-by: Colton Padden <colton.padden@vercel.com>
18 lines
624 B
TypeScript
18 lines
624 B
TypeScript
const LOCAL_SITE_HOST = "localhost:3000";
|
|
|
|
/** Returns the configured public site origin, with a non-secret local fallback. */
|
|
export const getSiteOrigin = () => {
|
|
const site = process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL ?? LOCAL_SITE_HOST;
|
|
|
|
if (site.includes("://")) {
|
|
const url = new URL(site);
|
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
throw new Error(`Unsupported site URL protocol: ${url.protocol}`);
|
|
}
|
|
return url.origin;
|
|
}
|
|
|
|
const protocol = site.startsWith("localhost") || site.startsWith("127.0.0.1") ? "http" : "https";
|
|
return `${protocol}://${site}`;
|
|
};
|