apiBase.ts 702 Bytes
/**
 * 美国版后端 API 根地址(不含末尾 /)。
 * - H5 开发:可在 .env.development 留空,配合 vite proxy 走同源 /api
 * - App / 生产:在 .env 中设置 VITE_US_API_BASE,例如 http://192.168.1.10:19001
 */
export function getApiBaseUrl(): string {
  const fromEnv = (import.meta.env.VITE_US_API_BASE as string | undefined)?.trim()
  if (fromEnv) return fromEnv.replace(/\/$/, '')
  if (import.meta.env.DEV && typeof window !== 'undefined') return ''
  return 'http://flus-test.3ffoodsafety.com'
}

export function buildApiUrl(path: string): string {
  const base = getApiBaseUrl()
  const p = path.startsWith('/') ? path : `/${path}`
  return base ? `${base}${p}` : p
}