diff --git a/services/frontend/src/lib/api/client.ts b/services/frontend/src/lib/api/client.ts index 0f3dfd2..253a2f7 100644 --- a/services/frontend/src/lib/api/client.ts +++ b/services/frontend/src/lib/api/client.ts @@ -11,8 +11,17 @@ export class ApiError extends Error { function getBaseUrl(): string { if (typeof window === "undefined") return ""; const protocol = window.location.protocol.replace(":", ""); - const host = window.location.host; - return `${protocol}://${host}`; + const hostname = window.location.hostname; + const port = window.location.port; + + // In local dev, frontend (port 3000) proxies API calls to backend (port 3001) + if (hostname === "localhost" || hostname === "127.0.0.1") { + const apiPort = port === "3000" ? "3001" : port; + return `${protocol}://${hostname}:${apiPort}`; + } + + // Production: nginx proxies /api/* to backend + return `${protocol}://${hostname}${port ? `:${port}` : ""}`; } export async function apiRequest( diff --git a/services/frontend/src/lib/ws/connection.ts b/services/frontend/src/lib/ws/connection.ts index 051ba42..4cd3614 100644 --- a/services/frontend/src/lib/ws/connection.ts +++ b/services/frontend/src/lib/ws/connection.ts @@ -5,8 +5,17 @@ type WsEventCallback = (event: WsEvent) => void; function getWsUrl(): string { if (typeof window === "undefined") return "ws://localhost:3001/ws"; const protocol = window.location.protocol === "https:" ? "wss" : "ws"; - const host = window.location.host; - return `${protocol}://${host}/ws`; + const hostname = window.location.hostname; + const port = window.location.port; + + // In local dev, WS server runs on port 3001 alongside the backend + if (hostname === "localhost" || hostname === "127.0.0.1") { + const wsPort = port === "3000" ? "3001" : port; + return `${protocol}://${hostname}:${wsPort}/ws`; + } + + // Production: nginx proxies /ws/* to backend + return `${protocol}://${hostname}${port ? `:${port}` : ""}/ws`; } export class WsConnection {