提交 | 用户 | 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 |
} |