mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-23 23:39:47 +08:00
refactor(projects): refactor service env config
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import type { ProxyOptions } from 'vite';
|
||||
import { createProxyPattern, createServiceConfig } from '../../env.config';
|
||||
import { createServiceConfig } from '../../src/utils/service';
|
||||
|
||||
/**
|
||||
* Set http proxy
|
||||
@ -11,29 +11,25 @@ export function createViteProxy(env: Env.ImportMeta) {
|
||||
|
||||
if (!isEnableHttpProxy) return undefined;
|
||||
|
||||
const { baseURL, otherBaseURL } = createServiceConfig(env);
|
||||
const { baseURL, proxyPattern, other } = createServiceConfig(env);
|
||||
|
||||
const defaultProxyPattern = createProxyPattern();
|
||||
const proxy: Record<string, ProxyOptions> = createProxyItem({ baseURL, proxyPattern });
|
||||
|
||||
const proxy: Record<string, ProxyOptions> = {
|
||||
[defaultProxyPattern]: {
|
||||
target: baseURL,
|
||||
changeOrigin: true,
|
||||
rewrite: path => path.replace(new RegExp(`^${defaultProxyPattern}`), '')
|
||||
}
|
||||
};
|
||||
|
||||
const otherURLEntries = Object.entries(otherBaseURL);
|
||||
|
||||
for (const [key, url] of otherURLEntries) {
|
||||
const proxyPattern = createProxyPattern(key as App.Service.OtherBaseURLKey);
|
||||
|
||||
proxy[proxyPattern] = {
|
||||
target: url,
|
||||
changeOrigin: true,
|
||||
rewrite: path => path.replace(new RegExp(`^${proxyPattern}`), '')
|
||||
};
|
||||
}
|
||||
other.forEach(item => {
|
||||
Object.assign(proxy, createProxyItem(item));
|
||||
});
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
function createProxyItem(item: App.Service.ServiceConfigItem) {
|
||||
const proxy: Record<string, ProxyOptions> = {};
|
||||
|
||||
proxy[item.proxyPattern] = {
|
||||
target: item.baseURL,
|
||||
changeOrigin: true,
|
||||
rewrite: path => path.replace(new RegExp(`^${item.proxyPattern}`), '')
|
||||
};
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
Reference in New Issue
Block a user