fix(dev): proxy admin through portless api

This commit is contained in:
2026-07-09 12:33:30 +08:00
parent a83fb53ecd
commit 45d06f56cd
5 changed files with 12 additions and 3 deletions
+1
View File
@@ -7,6 +7,7 @@ VITE_APP_ENV = 'development'
# 开发环境
VITE_APP_BASE_API = '/dev-api'
VITE_APP_PROXY_TARGET = 'https://wygj-api.localhost'
# 应用访问路径 例如使用前缀 /admin/
VITE_APP_CONTEXT_PATH = '/'
+3 -1
View File
@@ -5,6 +5,7 @@ import path from 'path';
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd());
const proxyTarget = env.VITE_APP_PROXY_TARGET || 'https://wygj-api.localhost';
return {
// 部署生产环境和开发环境下的URL。
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
@@ -24,8 +25,9 @@ export default defineConfig(({ mode, command }) => {
open: true,
proxy: {
[env.VITE_APP_BASE_API]: {
target: 'http://localhost:8080',
target: proxyTarget,
changeOrigin: true,
secure: false,
ws: true,
rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
}