diff --git a/web/src/core/api/resolve-service-url.ts b/web/src/core/api/resolve-service-url.ts index a87b777..26a1252 100644 --- a/web/src/core/api/resolve-service-url.ts +++ b/web/src/core/api/resolve-service-url.ts @@ -3,8 +3,25 @@ import { env } from "~/env"; +function getBaseURL(): string { + // If NEXT_PUBLIC_API_URL is explicitly configured, use it + if (env.NEXT_PUBLIC_API_URL) { + return env.NEXT_PUBLIC_API_URL; + } + + // Runtime detection: use the same hostname as the current page with port 8000 + // This allows cross-machine access without rebuilding (Issue #777) + if (typeof window !== "undefined") { + const { protocol, hostname } = window.location; + return `${protocol}//${hostname}:8000/api/`; + } + + // Fallback for SSR or when window is not available + return "http://localhost:8000/api/"; +} + export function resolveServiceURL(path: string) { - let BASE_URL = env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000/api/"; + let BASE_URL = getBaseURL(); if (!BASE_URL.endsWith("/")) { BASE_URL += "/"; }