Spaces:
Running
Running
File size: 493 Bytes
be47857 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | /**
* 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}`;
}
|