visualize_dataset / src /utils /internalFetch.ts
alexis779
feat: local dataset paths, API route, and versioned fetch routing
be47857
raw
history blame
493 Bytes
/**
* Server-side code (e.g. server actions) cannot use relative fetch URLs; prefix with the app origin.
*/
export function resolveInternalFetchUrl(url: string): string {
if (typeof window !== "undefined") return url;
if (url.startsWith("http://") || url.startsWith("https://")) return url;
if (!url.startsWith("/")) return url;
const base =
process.env.NEXT_PUBLIC_APP_URL?.replace(/\/$/, "") ??
`http://127.0.0.1:${process.env.PORT ?? "3000"}`;
return `${base}${url}`;
}