18 lines
638 B
TypeScript
18 lines
638 B
TypeScript
const trimTrailingSlash = (value: string) => value.replace(/\/$/, "");
|
|
|
|
export const siteUrl = trimTrailingSlash(
|
|
process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:8080",
|
|
);
|
|
|
|
export const apiBaseUrl = trimTrailingSlash(
|
|
process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:8000",
|
|
);
|
|
|
|
export const toAbsoluteUrl = (value?: string | null, fallbackBase = siteUrl) => {
|
|
if (!value) return undefined;
|
|
if (/^https?:\/\//i.test(value)) return value;
|
|
const normalizedBase = trimTrailingSlash(fallbackBase);
|
|
const normalizedPath = value.startsWith("/") ? value : `/${value}`;
|
|
return `${normalizedBase}${normalizedPath}`;
|
|
};
|