/** * Single source for API and WebSocket base URLs. * Uses VITE_API_URL so one env var works for both REST and WebSocket. * * When VITE_API_URL is defined (even as empty string), use it as-is. * Empty string = same origin (for HF Spaces / single-container deploy). * Only fall back to localhost:8000 when the var is completely undefined. */ const envVal = import.meta.env.VITE_API_URL; const API_BASE_URL = typeof envVal === 'string' ? envVal.trim().replace(/\/+$/, '') : 'http://localhost:8000'; /** WebSocket base URL derived from API URL (http -> ws, same host/port) */ const WS_BASE_URL = API_BASE_URL ? API_BASE_URL.replace(/^http/, 'ws') : `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}`; export { API_BASE_URL, WS_BASE_URL };