2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 14:57:16 +08:00
Files
panel/web/build/config/proxy.ts
2024-10-20 19:55:14 +08:00

21 lines
612 B
Go

import type { ProxyOptions } from 'vite'
import { getProxyConfigs } from '../../settings/proxy-config'
export function createViteProxy(isUseProxy = true, proxyType: ProxyType) {
if (!isUseProxy) return undefined
const proxyConfigs = getProxyConfigs(proxyType)
const proxy: Record<string, string | ProxyOptions> = {}
proxyConfigs.forEach((proxyConfig) => {
proxy[proxyConfig.prefix] = {
target: proxyConfig.target,
secure: proxyConfig.secure,
changeOrigin: true,
rewrite: (path: string) => path.replace(new RegExp(`^${proxyConfig.prefix}`), '')
}
})
return proxy
}