| 123456789101112131415161718192021222324252627282930313233 |
- import type { ProxyOptions } from "vite";
- type ProxyItem = [string, string];
- type ProxyList = ProxyItem[];
- type ProxyTargetList = Record<string, ProxyOptions>;
- /**
- * 创建代理,用于解析 .env.development 代理配置
- * @param list
- */
- export function createProxy(list: ProxyList = []) {
- const ret: ProxyTargetList = {};
- for (const [prefix, target] of list) {
- const httpsRE = /^https:\/\//;
- const isHttps = httpsRE.test(target);
- // https://github.com/http-party/node-http-proxy#options
- ret[prefix] = {
- target: target,
- changeOrigin: true,
- ws: true,
- rewrite: path => path.replace(new RegExp(`^${prefix}`), ""),
- /** 大视频上传/审核经代理时避免过早断开(10 分钟) */
- timeout: 600000,
- proxyTimeout: 600000,
- // https is require secure=false
- ...(isHttps ? { secure: false } : {})
- };
- }
- return ret;
- }
|