function stripTrailingSlash(url) { return url.replace(/\/+$/, '') } /** * Backend URL for production (e.g. Hugging Face Space). Override with `VITE_API_BASE` * in Vercel Project → Environment Variables if needed. * In development, empty base keeps `/users`, `/response`, … as relative URLs → Vite proxy. */ export function getApiBase() { const fromEnv = import.meta.env.VITE_API_BASE if (fromEnv != null && String(fromEnv).trim() !== '') { return stripTrailingSlash(String(fromEnv).trim()) } if (import.meta.env.PROD) { return 'https://cuiconnect-backend.hf.space' } return '' } /** * @param {string} path - absolute path (e.g. `/users/login`) */ export function apiUrl(path) { const base = getApiBase() const p = path.startsWith('/') ? path : `/${path}` return base ? `${base}${p}` : p }