平安校园
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

3 个月前
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. }