first
This commit is contained in:
1
build/config/index.ts
Normal file
1
build/config/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './proxy';
|
||||
18
build/config/proxy.ts
Normal file
18
build/config/proxy.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { ProxyOptions } from 'vite';
|
||||
|
||||
type ProxyTargetList = Record<string, ProxyOptions>;
|
||||
|
||||
export const createViteProxy = (env: Record<string, string>) => {
|
||||
const { VITE_APP_PROXY, VITE_API_PREFIX, VITE_API_BASE_URL } = env;
|
||||
// 不使用代理直接返回
|
||||
if (!JSON.parse(VITE_APP_PROXY)) return undefined;
|
||||
const proxy: ProxyTargetList = {
|
||||
[VITE_API_PREFIX]: {
|
||||
target: VITE_API_BASE_URL,
|
||||
changeOrigin: true,
|
||||
// 不移除 /api 前缀,因为后端API路径本身就包含 /api
|
||||
// rewrite: path => path.replace(new RegExp(`^${VITE_API_PREFIX}`), ''),
|
||||
},
|
||||
};
|
||||
return proxy;
|
||||
};
|
||||
Reference in New Issue
Block a user