You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
/**
|
|
|
|
|
* 获取 API 基础路径
|
|
|
|
|
* 当 VITE_BASE_URL 为 '/' 或空时,使用相对路径(直接使用 VITE_API_URL)
|
|
|
|
|
* 否则拼接 VITE_BASE_URL + VITE_API_URL
|
|
|
|
|
*/
|
|
|
|
|
const getBaseUrl = (): string => {
|
|
|
|
|
const baseUrl = import.meta.env.VITE_BASE_URL
|
|
|
|
|
const apiUrl = import.meta.env.VITE_API_URL
|
|
|
|
|
console.log('[API Config] VITE_BASE_URL:', baseUrl)
|
|
|
|
|
console.log('[API Config] VITE_API_URL:', apiUrl)
|
|
|
|
|
// 如果 baseUrl 是 '/' 或空,则使用相对路径
|
|
|
|
|
if (!baseUrl || baseUrl === '/') {
|
|
|
|
|
console.log('[API Config] Using relative path:', apiUrl)
|
|
|
|
|
return apiUrl
|
|
|
|
|
}
|
|
|
|
|
const result = baseUrl + apiUrl
|
|
|
|
|
console.log('[API Config] Using absolute path:', result)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const config: {
|
|
|
|
|
base_url: string
|
|
|
|
|
result_code: number | string
|
|
|
|
|
default_headers: AxiosHeaders
|
|
|
|
|
request_timeout: number
|
|
|
|
|
} = {
|
|
|
|
|
/**
|
|
|
|
|
* api请求基础路径
|
|
|
|
|
*/
|
|
|
|
|
base_url: getBaseUrl(),
|
|
|
|
|
/**
|
|
|
|
|
* 接口成功返回状态码
|
|
|
|
|
*/
|
|
|
|
|
result_code: 200,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 接口请求超时时间
|
|
|
|
|
*/
|
|
|
|
|
request_timeout: 30000,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 默认接口请求类型
|
|
|
|
|
* 可选值:application/x-www-form-urlencoded multipart/form-data
|
|
|
|
|
*/
|
|
|
|
|
default_headers: 'application/json'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export { config }
|