Files
pda-overseas-uniapp/src/config/runtime.js
T

33 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-08-25 00:24:57 +08:00
const runtimeEnvironment = import.meta.env || {}
const configuredAuthApiRoot = runtimeEnvironment.VITE_AUTH_API_BASE_URL || ''
const configuredOverseasApiRoot = runtimeEnvironment.VITE_OVERSEAS_API_BASE_URL || ''
2026-08-25 19:56:47 +08:00
const development = Boolean(runtimeEnvironment.DEV)
2026-08-20 20:10:20 +08:00
2026-08-26 15:24:51 +08:00
let selectedAuthApiRoot = configuredAuthApiRoot || '/api'
let selectedOverseasApiRoot = configuredOverseasApiRoot || '/overseas-api'
2026-08-26 15:59:08 +08:00
const nativeRuntime = typeof plus !== 'undefined'
|| (typeof location !== 'undefined' && location.protocol === 'file:')
2026-08-26 15:24:51 +08:00
// H5 must stay same-origin and use Vite's CORS-safe proxy; App builds keep the absolute API roots above.
// #ifdef H5
selectedAuthApiRoot = runtimeEnvironment.VITE_H5_AUTH_API_BASE_URL || '/api'
selectedOverseasApiRoot = runtimeEnvironment.VITE_H5_OVERSEAS_API_BASE_URL || '/overseas-api'
// #endif
2026-08-26 15:59:08 +08:00
// HBuilderX/App 基座 can expose a file:// location; never allow a relative API
// root there, even if a stale H5 bundle or compiler flag was reused.
if (nativeRuntime) {
selectedAuthApiRoot = configuredAuthApiRoot || selectedAuthApiRoot
2026-09-17 13:36:08 +08:00
// Native file:// builds cannot use the H5-only /overseas-api Vite proxy.
// Keep the missing value explicit so the request layer can report a useful
// configuration error instead of surfacing an opaque uploadFile:fail.
selectedOverseasApiRoot = configuredOverseasApiRoot || ''
2026-08-26 15:59:08 +08:00
}
2026-08-26 15:24:51 +08:00
export const API_ROOT = String(selectedAuthApiRoot).replace(/\/$/, '')
export const OVERSEAS_API_ROOT = String(selectedOverseasApiRoot).replace(/\/$/, '')
2026-08-25 19:56:47 +08:00
export const DEV_LOGIN = Object.freeze({
username: development ? String(runtimeEnvironment.VITE_PDA_DEV_USERNAME || '') : '',
password: development ? String(runtimeEnvironment.VITE_PDA_DEV_PASSWORD || '') : ''
})