Blame view

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

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