vben
2020-10-18 7101587b9676c91e9079044a096df08848f1f602
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type ProxyItem = [string, string];
 
type ProxyList = ProxyItem[];
 
const reg = /^https:\/\//;
export function createProxy(list: ProxyList = []) {
  const ret: any = {};
  for (const [prefix, target] of list) {
    const isHttps = reg.test(target);
 
    ret[prefix] = {
      target: target,
      changeOrigin: true,
      rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
      ...(isHttps ? { secure: false } : {}),
    };
  }
  return ret;
}