mirror of
https://github.com/chansee97/nova-admin.git
synced 2026-07-03 15:18:14 +08:00
Compare commits
No commits in common. "3e7fb6fa166e2b43b4fb5f70fe88c4982d32f70a" and "4687b32dc8359e7cd3dbccdcf6d749563f1ebbb2" have entirely different histories.
3e7fb6fa16
...
4687b32dc8
@ -34,6 +34,8 @@ export interface ServiceProxyPluginOptions {
|
||||
serviceConfig: FullServiceConfig
|
||||
/** 代理路径前缀(可选,默认为 'proxy-') */
|
||||
proxyPrefix?: string
|
||||
/** 开发环境名称(可选,默认为 'development') */
|
||||
devEnvName?: ServiceEnvType
|
||||
/** 是否启用代理配置 */
|
||||
enableProxy?: boolean
|
||||
/** 环境变量名(可选,默认为 '__URL_MAP__') */
|
||||
@ -45,6 +47,7 @@ export interface ServiceProxyPluginOptions {
|
||||
export default function createServiceProxyPlugin(options: ServiceProxyPluginOptions) {
|
||||
const {
|
||||
serviceConfig,
|
||||
devEnvName = 'development',
|
||||
proxyPrefix = 'proxy-',
|
||||
enableProxy = true,
|
||||
envName = '__URL_MAP__',
|
||||
@ -63,8 +66,10 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
}
|
||||
|
||||
if (!enableProxy || !isDev) {
|
||||
// 在非开发环境下,根据构建模式选择正确的环境配置
|
||||
const targetEnv = isDev ? devEnvName : mode
|
||||
const rawMapping: ProxyMapping = {}
|
||||
const envConfig = serviceConfig[mode]
|
||||
const envConfig = serviceConfig[targetEnv]
|
||||
|
||||
if (envConfig) {
|
||||
Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => {
|
||||
@ -76,7 +81,7 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
console.warn(`[auto-proxy] 已加载 ${Object.keys(envConfig).length} 个服务地址`)
|
||||
}
|
||||
else {
|
||||
console.warn(`[auto-proxy] 未找到环境 "${mode}" 的配置`)
|
||||
console.warn(`[auto-proxy] 未找到环境 "${targetEnv}" 的配置`)
|
||||
}
|
||||
|
||||
config.define[envName] = JSON.stringify(rawMapping)
|
||||
@ -88,9 +93,9 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
return
|
||||
}
|
||||
|
||||
console.warn(`[auto-proxy] 已加载${mode}模式 ${Object.keys(serviceConfig[mode]).length} 个服务地址`)
|
||||
console.warn(`[auto-proxy] 已加载${devEnvName}模式 ${Object.keys(serviceConfig[devEnvName]).length} 个服务地址`)
|
||||
|
||||
const { proxyConfig, proxyMapping } = generateProxyFromServiceConfig(serviceConfig, mode, proxyPrefix)
|
||||
const { proxyConfig, proxyMapping } = generateProxyFromServiceConfig(serviceConfig, devEnvName, proxyPrefix)
|
||||
|
||||
Object.entries(proxyMapping).forEach(([serviceName, proxyItem]) => {
|
||||
console.warn(`[auto-proxy] 服务: ${serviceName} | 代理地址: ${proxyItem.path} | 实际地址: ${proxyItem.rawPath}`)
|
||||
|
||||
@ -85,6 +85,7 @@ export function createVitePlugins(env: ImportMetaEnv) {
|
||||
AutoProxy({
|
||||
enableProxy: env.VITE_HTTP_PROXY === 'Y',
|
||||
serviceConfig,
|
||||
devEnvName: 'dev',
|
||||
dts: 'src/typings/auto-proxy.d.ts',
|
||||
}),
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user