/** Browser: `/api/...` (same origin). Server: INTERNAL_API_URL → NEXT_PUBLIC_API_URL → loopback. */ export function apiUrl(path: string): string { const p = path.startsWith("/") ? path : `/${path}`; if (typeof window !== "undefined") { return `/api${p}`; } const base = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:4000/api"; return `${base}${p}`; }