/** * 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}`; }