You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
550 B
TypeScript
21 lines
550 B
TypeScript
|
1 year ago
|
import type { ProxyOptions } from 'vite';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 设置网络代理
|
||
|
|
* @param isOpenProxy - 是否开启代理
|
||
|
|
* @param envConfig - env环境配置
|
||
|
|
*/
|
||
|
|
export function createViteProxy(isOpenProxy: boolean, envConfig: ServiceEnvConfigWithProxyPattern) {
|
||
|
|
if (!isOpenProxy) return undefined;
|
||
|
|
|
||
|
|
const proxy: Record<string, string | ProxyOptions> = {
|
||
|
|
[envConfig.proxyPattern]: {
|
||
|
|
target: envConfig.url,
|
||
|
|
changeOrigin: true,
|
||
|
|
rewrite: path => path.replace(new RegExp(`^${envConfig.proxyPattern}`), '')
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
return proxy;
|
||
|
|
}
|