This commit is contained in:
2026-09-29 17:56:05 +08:00
parent ef5c8250c5
commit 0aaf855ce2
13 changed files with 121 additions and 145 deletions
+7 -24
View File
@@ -1,31 +1,14 @@
const runtimeEnvironment = import.meta.env || {}
const configuredAuthApiRoot = runtimeEnvironment.VITE_AUTH_API_BASE_URL || ''
const configuredOverseasApiRoot = runtimeEnvironment.VITE_OVERSEAS_API_BASE_URL || ''
const configuredApiRoot = runtimeEnvironment.VITE_API_BASE_URL || ''
const development = Boolean(runtimeEnvironment.DEV)
let selectedAuthApiRoot = configuredAuthApiRoot || '/api'
let selectedOverseasApiRoot = configuredOverseasApiRoot || '/overseas-api'
let selectedApiRoot = configuredApiRoot || '/api'
// #ifdef H5
selectedApiRoot = runtimeEnvironment.VITE_H5_API_BASE_URL || '/api'
// #endif
const nativeRuntime = typeof plus !== 'undefined'
|| (typeof location !== 'undefined' && location.protocol === 'file:')
// 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
// 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
// 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 || ''
}
export const API_ROOT = String(selectedAuthApiRoot).replace(/\/$/, '')
export const OVERSEAS_API_ROOT = String(selectedOverseasApiRoot).replace(/\/$/, '')
if (nativeRuntime) selectedApiRoot = configuredApiRoot || ''
export const API_ROOT = String(selectedApiRoot).replace(/\/$/, '')
export const DEV_LOGIN = Object.freeze({
username: development ? String(runtimeEnvironment.VITE_PDA_DEV_USERNAME || '') : '',
password: development ? String(runtimeEnvironment.VITE_PDA_DEV_PASSWORD || '') : ''