proxy.ts 466 B

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