export const getApiBaseUrl = (): string => { const envVal = import.meta.env.VITE_API_BASE_URL; // If env variable is set and not a localhost fallback, use it directly if (envVal && !envVal.includes('localhost') && !envVal.includes('127.0.0.1')) { return envVal; } // Fallback: use the current window origin (works on HuggingFace since // frontend and backend are served from the same domain via Nginx proxy) return window.location.origin; }; export const getWsUrl = (): string => { const envVal = import.meta.env.VITE_WS_URL; let url = (envVal && !envVal.includes('localhost')) ? envVal : getApiBaseUrl(); // SockJS requires 'http:' or 'https:' scheme, not 'ws:' or 'wss:' if (url.startsWith('ws://')) { url = url.replace(/^ws:\/\//i, 'http://'); } else if (url.startsWith('wss://')) { url = url.replace(/^wss:\/\//i, 'https://'); } return url; };