平安校园
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.

преди 2 месеца
123456789101112131415161718192021222324252627282930
  1. import type { ProxyOptions } from "vite";
  2. type ProxyItem = [string, string];
  3. type ProxyList = ProxyItem[];
  4. type ProxyTargetList = Record<string, ProxyOptions>;
  5. /**
  6. * 创建代理,用于解析 .env.development 代理配置
  7. * @param list
  8. */
  9. export function createProxy(list: ProxyList = []) {
  10. const ret: ProxyTargetList = {};
  11. for (const [prefix, target] of list) {
  12. const httpsRE = /^https:\/\//;
  13. const isHttps = httpsRE.test(target);
  14. // https://github.com/http-party/node-http-proxy#options
  15. ret[prefix] = {
  16. target: target,
  17. changeOrigin: true,
  18. ws: true,
  19. rewrite: path => path.replace(new RegExp(`^${prefix}`), ""),
  20. // https is require secure=false
  21. ...(isHttps ? { secure: false } : {})
  22. };
  23. }
  24. return ret;
  25. }