diff --git a/src/services/api.js b/src/services/api.js index feed8ba..915d543 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -1,22 +1,9 @@ import axios from 'axios' - -// 根据环境变量确定基础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' - } -} +import config from './config' // 创建 axios 实例 const apiClient = axios.create({ - baseURL: getBaseURL(), + baseURL: config.API_URL, timeout: 10000, // 请求超时时间 headers: { 'Content-Type': 'application/json' diff --git a/src/services/config.js b/src/services/config.js new file mode 100644 index 0000000..20919fb --- /dev/null +++ b/src/services/config.js @@ -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'] \ No newline at end of file