From 46f2d698003ecb1ad618412b89aa18152286b439 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 11 May 2026 22:34:16 +0800 Subject: [PATCH] feat: modify vite config for backend frontend decouple dev --- frontend/vite.config.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 4217010..6a5e119 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -15,4 +15,23 @@ export default defineConfig({ '@': fileURLToPath(new URL('./src', import.meta.url)) }, }, + + // 项目基础路径(对应 Nginx 路由到的 /web 前缀) + base: '/web/', + + server: { + port: 5173, // 开发服务器默认端口 + open: '/web/', // 启动时自动打开 /web 路径 + + // 核心:代理配置(对应 Nginx 的 /api -> Go 服务) + proxy: { + // 精细控制路由,对齐生产环境 + '^/api/(.*)$': { + target: 'http://127.0.0.1:8848', + changeOrigin: true, + // 路径重写/api/user -> /user + rewrite: (path) => path.replace(/^\/api\//, '/'), + } + }, + })