proxy.ts 445 B

12345678910111213141516171819
  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. }