refactor(projects): update service and proxy config

This commit is contained in:
Soybean
2023-03-07 07:52:05 +08:00
parent 1ef1b6bda9
commit 8debfe7e95
4 changed files with 23 additions and 32 deletions

View File

@ -5,19 +5,14 @@ import type { ProxyOptions } from 'vite';
* @param isOpenProxy - 是否开启代理
* @param envConfig - env环境配置
*/
export function createViteProxy(isOpenProxy: boolean, envConfig: ServiceEnvConfig) {
export function createViteProxy(isOpenProxy: boolean, envConfig: ServiceEnvConfigWithProxyPattern) {
if (!isOpenProxy) return undefined;
const proxy: Record<string, string | ProxyOptions> = {
[envConfig.urlPattern]: {
[envConfig.proxyPattern]: {
target: envConfig.url,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`^${envConfig.urlPattern}`), '')
},
[envConfig.secondUrlPattern]: {
target: envConfig.secondUrl,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`^${envConfig.secondUrlPattern}`), '')
rewrite: path => path.replace(new RegExp(`^${envConfig.proxyPattern}`), '')
}
};