mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 22:07:16 +08:00
21 lines
612 B
Go
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
|
|
}
|