proxy.ts 547 B

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