fix(build): fix environment variable configuration file failure

This commit is contained in:
vben
2020-12-22 22:13:03 +08:00
parent e6db0d39b9
commit bd7b53f14a
19 changed files with 158 additions and 245 deletions

View File

@@ -2,21 +2,31 @@ type ProxyItem = [string, string];
type ProxyList = ProxyItem[];
const reg = /^https:\/\//;
type ProxyTargetList = Record<
string,
{
target: string;
changeOrigin: boolean;
rewrite: (path: string) => any;
secure?: boolean;
}
>;
const httpsRE = /^https:\/\//;
/**
* Generate proxy
* @param list
*/
export function createProxy(list: ProxyList = []) {
const ret: any = {};
const ret: ProxyTargetList = {};
for (const [prefix, target] of list) {
const isHttps = reg.test(target);
const isHttps = httpsRE.test(target);
ret[prefix] = {
target: target,
changeOrigin: true,
rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
// https is require secure=false
...(isHttps ? { secure: false } : {}),
};