This commit is contained in:
aaron 2025-03-01 22:18:49 +08:00
parent 896123b3a2
commit 6c1864b51f
2 changed files with 15 additions and 15 deletions

View File

@ -1,22 +1,9 @@
import axios from 'axios' import axios from 'axios'
import config from './config'
// 根据环境变量确定基础URL
const getBaseURL = () => {
// 从环境变量 APP_ENV 获取当前的环境
const appEnv = process.env.APP_ENV || 'local'
switch (appEnv) {
case 'dev':
return 'https://api-dev.beefast.co'
case 'prd':
return 'https://api.beefast.co'
default:
return 'http://localhost:8000'
}
}
// 创建 axios 实例 // 创建 axios 实例
const apiClient = axios.create({ const apiClient = axios.create({
baseURL: getBaseURL(), baseURL: config.API_URL,
timeout: 10000, // 请求超时时间 timeout: 10000, // 请求超时时间
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'

13
src/services/config.js Normal file
View File

@ -0,0 +1,13 @@
const env = {
development: {
API_URL: 'http://localhost:8000'
},
testing: {
API_URL: process.env.VUE_APP_API_URL || 'https://api-dev.beefast.co'
},
production: {
API_URL: process.env.VUE_APP_API_URL || 'https://api.beefast.co'
}
}
export default env[process.env.NODE_ENV || 'development']