You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
445 B

  1. type ProxyItem = [string, string];
  2. type ProxyList = ProxyItem[];
  3. const regExps = (value: string, reg: string): string => {
  4. return value.replace(new RegExp(reg, "g"), "");
  5. };
  6. export function createProxy(list: ProxyList = []) {
  7. const ret: any = {};
  8. for (const [prefix, target] of list) {
  9. ret[prefix] = {
  10. target: target,
  11. changeOrigin: true,
  12. rewrite: (path: string) => regExps(path, prefix)
  13. };
  14. }
  15. return ret;
  16. }