File size: 831 Bytes
2b32e9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}