Files
SEONexusAdmin/build/proxy.ts
Your Name 845d68110b debug
2026-04-15 12:00:09 +08:00

25 lines
662 B
TypeScript

import type { ProxyOptions } from "vite";
type ProxyItem = [string, string];
type ProxyList = ProxyItem[];
type ProxyTargetList = Record<string, ProxyOptions>;
export function createProxy(list: ProxyList = []) {
const ret: ProxyTargetList = {};
for (const [prefix, target] of list) {
const httpsRE = /^https:\/\//;
const isHttps = httpsRE.test(target);
ret[prefix] = {
target: target,
changeOrigin: true,
ws: true,
rewrite: path => path.replace(new RegExp(`^${prefix}`), ""),
...(isHttps ? { secure: false } : {})
};
}
return ret;
}