feat: 更新 API 前缀配置,调整 Vite 代理设置以匹配新环境
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
VITE_API_PREFIX=/app_03/api
|
||||
VITE_UPLOADS_PREFIX=/uploads
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ const TOKEN_KEY = "auth_token";
|
||||
|
||||
const env = (import.meta as any).env || {};
|
||||
const API_PREFIX: string = (env.VITE_API_PREFIX as string) || "/api";
|
||||
const APP_BASE_URL: string = (env.BASE_URL as string) || "/";
|
||||
// APP_BASE_URL = basename = 从 API_PREFIX 提取("/app_03/api" → "/app_03")
|
||||
const APP_BASE_URL: string = API_PREFIX.replace(/\/api\/?$/, '') || '/';
|
||||
|
||||
function joinPrefix(prefix: string, path: string) {
|
||||
const p = prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
||||
|
||||
@@ -33,11 +33,12 @@ export default defineConfig(({ mode }) => {
|
||||
allowedHosts: ['.trycloudflare.com', '.loca.lt'],
|
||||
proxy: {
|
||||
[apiPrefix]: {
|
||||
target: 'http://localhost:8000',
|
||||
target: 'http://localhost:8030',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/app_03\/api/, '/api'),
|
||||
},
|
||||
[uploadsPrefix]: {
|
||||
target: 'http://localhost:8000',
|
||||
target: 'http://localhost:8030',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user