fix: read VITE_API_BASE_URL from .env for Vite dev proxy (fixes #480)
The Vite development proxy target was hardcoded to http://localhost:5001, ignoring the VITE_API_BASE_URL environment variable that the axios client already respects. This caused the dev proxy to still route to localhost even when users configured a remote or custom backend address. - Use loadEnv() in vite.config.js to read VITE_API_BASE_URL from the project root .env file and pass it as the proxy target (fallback: localhost:5001) - Document VITE_API_BASE_URL in .env.example so users know the variable exists
This commit is contained in:
parent
fa0f6519b1
commit
9961d59c78
|
|
@ -14,3 +14,9 @@ ZEP_API_KEY=your_zep_api_key_here
|
||||||
LLM_BOOST_API_KEY=your_api_key_here
|
LLM_BOOST_API_KEY=your_api_key_here
|
||||||
LLM_BOOST_BASE_URL=your_base_url_here
|
LLM_BOOST_BASE_URL=your_base_url_here
|
||||||
LLM_BOOST_MODEL_NAME=your_model_name_here
|
LLM_BOOST_MODEL_NAME=your_model_name_here
|
||||||
|
|
||||||
|
# ===== 前端 / 部署配置(可选)=====
|
||||||
|
# 后端 API 地址(axios 客户端 + Vite 开发代理均读取此变量)
|
||||||
|
# 默认值:http://localhost:5001
|
||||||
|
# 若后端运行在其他主机或端口,请取消注释并修改为对应地址
|
||||||
|
# VITE_API_BASE_URL=http://localhost:5001
|
||||||
|
|
@ -1,24 +1,29 @@
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
plugins: [vue()],
|
const env = loadEnv(mode, path.resolve(__dirname, '..'), '')
|
||||||
resolve: {
|
const backendUrl = env.VITE_API_BASE_URL || 'http://localhost:5001'
|
||||||
alias: {
|
|
||||||
'@': path.resolve(__dirname, 'src'),
|
return {
|
||||||
'@locales': path.resolve(__dirname, '../locales')
|
plugins: [vue()],
|
||||||
}
|
resolve: {
|
||||||
},
|
alias: {
|
||||||
server: {
|
'@': path.resolve(__dirname, 'src'),
|
||||||
port: 3000,
|
'@locales': path.resolve(__dirname, '../locales')
|
||||||
open: true,
|
}
|
||||||
proxy: {
|
},
|
||||||
'/api': {
|
server: {
|
||||||
target: 'http://localhost:5001',
|
port: 3000,
|
||||||
changeOrigin: true,
|
open: true,
|
||||||
secure: false
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: backendUrl,
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue