backend / frontend /src /config /apiBase.js
muhammadhasnain100's picture
Cursor
chatbot: tighten web search prompt (concise, admissions site for MS/PhD)
2b32e9d
Raw History Blame Contribute Delete
831 Bytes
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
}