修正开发环境和远程生产环境切换的bug。
This commit is contained in:
@@ -58,23 +58,16 @@ export function getApiEnv() {
|
||||
}
|
||||
|
||||
// 导出完整的 API URL 构建函数
|
||||
// H5环境下:local环境直接使用完整URL(避免代理配置问题),prod环境使用代理路径
|
||||
// H5环境下:local / prod 均直接使用完整URL,避免依赖本地代理
|
||||
// 其他环境使用完整URL
|
||||
export function getApiUrl(path = '') {
|
||||
const apiPath = path.startsWith('/') ? path : `/${path}`
|
||||
// #ifdef H5
|
||||
// H5环境下,local环境直接使用完整URL,prod环境使用代理路径
|
||||
if (API_ENV === 'local') {
|
||||
// local环境直接使用完整URL,避免代理配置问题
|
||||
const fullPath = apiPath.startsWith('/') ? apiPath.slice(1) : apiPath
|
||||
const fullUrl = `${API_BASE_URL}${fullPath}`
|
||||
console.log('[API Config] H5环境(local)直接使用完整URL:', fullUrl)
|
||||
return fullUrl
|
||||
} else {
|
||||
// prod环境使用代理路径,代理配置在manifest.json中
|
||||
console.log('[API Config] H5环境(prod)使用代理路径:', apiPath, '(代理target:', API_BASE_URL.replace(/\/$/, ''), ')')
|
||||
return apiPath
|
||||
}
|
||||
// H5环境下,local / prod 都返回完整URL,确保 prod 时直接请求远程服务器
|
||||
const fullPath = apiPath.startsWith('/') ? apiPath.slice(1) : apiPath
|
||||
const fullUrl = `${API_BASE_URL}${fullPath}`
|
||||
console.log(`[API Config] H5环境(${API_ENV})直接使用完整URL:`, fullUrl)
|
||||
return fullUrl
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
// 其他环境使用完整URL
|
||||
|
||||
Reference in New Issue
Block a user