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