feat: modify vite config for backend frontend decouple dev
This commit is contained in:
@@ -15,4 +15,23 @@ export default defineConfig({
|
|||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
'@': 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\//, '/'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user