gf-vben-admin/build/vite/proxy.ts

26 lines
547 B
TypeScript
Raw Normal View History

2020-09-28 20:19:10 +08:00
type ProxyItem = [string, string];
type ProxyList = ProxyItem[];
2020-10-18 21:55:21 +08:00
const reg = /^https:\/\//;
2020-10-29 23:01:11 +08:00
/**
* Generate proxy
* @param list
*/
2020-10-11 01:18:38 +08:00
export function createProxy(list: ProxyList = []) {
2020-09-28 20:19:10 +08:00
const ret: any = {};
for (const [prefix, target] of list) {
2020-10-18 21:55:21 +08:00
const isHttps = reg.test(target);
2020-09-28 20:19:10 +08:00
ret[prefix] = {
target: target,
changeOrigin: true,
rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
2020-10-29 23:01:11 +08:00
// https is require secure=false
2020-10-18 21:55:21 +08:00
...(isHttps ? { secure: false } : {}),
2020-09-28 20:19:10 +08:00
};
}
return ret;
}