平安校园
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

31 lignes
776 B

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