Files
2026-08-04 15:34:34 +08:00

32 lines
881 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig(({ mode }) => {
// 读取 frontend/.env* 与进程环境(start.sh 会注入根目录 .env
const env = loadEnv(mode, process.cwd(), '')
const apiTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:18080'
const port = Number(env.PORT || env.FRONTEND_PORT || 15173)
return {
plugins: [react()],
server: {
port,
proxy: {
// 只代理真实后端 API,避免 /api-debug 这类前端路由刷新时被误转发到后端。
'^/api(/|$)': {
target: apiTarget,
changeOrigin: true,
},
'/uploads': {
target: apiTarget,
changeOrigin: true,
},
'/health': {
target: apiTarget,
changeOrigin: true,
},
},
},
}
})