refactor(all): migrate from React to Next.js
This commit is contained in:
17
src/lib/site.ts
Normal file
17
src/lib/site.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
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}`;
|
||||
};
|
||||
Reference in New Issue
Block a user