Blame view

build/vite/proxy.ts 547 Bytes
陈文彬 authored
1
2
3
4
type ProxyItem = [string, string];

type ProxyList = ProxyItem[];
vben authored
5
const reg = /^https:\/\//;
vben authored
6
7
8
9
10

/**
 * Generate proxy
 * @param list
 */
nebv authored
11
export function createProxy(list: ProxyList = []) {
陈文彬 authored
12
13
  const ret: any = {};
  for (const [prefix, target] of list) {
vben authored
14
15
    const isHttps = reg.test(target);
陈文彬 authored
16
17
18
19
    ret[prefix] = {
      target: target,
      changeOrigin: true,
      rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
vben authored
20
      // https is require secure=false
vben authored
21
      ...(isHttps ? { secure: false } : {}),
陈文彬 authored
22
23
24
25
    };
  }
  return ret;
}