Blame view

美国版/Food Labeling Management App UniApp/src/utils/apiBase.ts 702 Bytes
6faaf539   杨鑫   APP 登录门店对接
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /**
   * 美国版后端 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
  }