refactor(env): 优化环境变量配置和请求基地址设置

- 移除 request.ts 中的重复 baseURL 配置
- 在 vite.config.ts 中添加默认的 API基地址和前端端口- 更新请求基地址为相对路径,提高可维护性
This commit is contained in:
黄建武
2025-05-09 13:23:29 +08:00
parent 048a3b70df
commit da645291a2
2 changed files with 3 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
import axios from 'axios'
const baseURL=import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000'
const request = axios.create({
baseURL: baseURL+'/api',
baseURL: '/api',
timeout: 10000,
})

View File

@@ -7,8 +7,8 @@ import tailwindcss from '@tailwindcss/vite'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd() + '/../')
const apiBaseUrl = env.VITE_API_BASE_URL
const port = env.FRONTEND_PORT || 3015
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://localhost:8000'
const port = env.VITE_FRONTEND_PORT || 3015
return {
base: './',