vben
2020-10-29 2f1fbf8e487fdae4db5c144d97f9d20e42bb1603
提交 | 用户 | age
2f6253 1 type ProxyItem = [string, string];
2
3 type ProxyList = ProxyItem[];
4
710158 5 const reg = /^https:\/\//;
2f1fbf 6
V 7 /**
8  * Generate proxy
9  * @param list
10  */
526e6c 11 export function createProxy(list: ProxyList = []) {
2f6253 12   const ret: any = {};
13   for (const [prefix, target] of list) {
710158 14     const isHttps = reg.test(target);
V 15
2f6253 16     ret[prefix] = {
17       target: target,
18       changeOrigin: true,
19       rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
2f1fbf 20       // https is require secure=false
710158 21       ...(isHttps ? { secure: false } : {}),
2f6253 22     };
23   }
24   return ret;
25 }