refactor: 简化proxy配置
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
/**
|
||||
* * 此处定义的是全局常量,启动或打包后将添加到window中
|
||||
* https://vitejs.cn/config/#define
|
||||
*/
|
||||
|
||||
// 项目构建时间
|
||||
const _BUILD_TIME_ = JSON.stringify(dayjs().format('YYYY-MM-DD HH:mm:ss'))
|
||||
|
||||
export const viteDefine = {
|
||||
_BUILD_TIME_,
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
export * from './define'
|
||||
export * from './proxy'
|
@@ -1,15 +0,0 @@
|
||||
import { getProxyConfig } from '../../settings'
|
||||
|
||||
export function createViteProxy(isUseProxy = true, proxyType) {
|
||||
if (!isUseProxy) return undefined
|
||||
|
||||
const proxyConfig = getProxyConfig(proxyType)
|
||||
const proxy = {
|
||||
[proxyConfig.prefix]: {
|
||||
target: proxyConfig.target,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^${proxyConfig.prefix}`), ''),
|
||||
},
|
||||
}
|
||||
return proxy
|
||||
}
|
@@ -1 +1,33 @@
|
||||
export const OUTPUT_DIR = 'dist'
|
||||
|
||||
export const PROXY_CONFIG = {
|
||||
/**
|
||||
* @desc 替换匹配值
|
||||
* @请求路径 http:localhost:3100/api/user
|
||||
* @转发路径 http://localhost:8080/user
|
||||
*/
|
||||
'/api': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp('^/api'), ''),
|
||||
},
|
||||
/**
|
||||
* @desc 不替换匹配值
|
||||
* @请求路径 http:localhost:3100/api/v2/user
|
||||
* @转发路径 http://localhost:8080/api/v2/user
|
||||
*/
|
||||
'/api/v2': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
},
|
||||
/**
|
||||
* @desc 替换部分匹配值
|
||||
* @请求路径 http:localhost:3100/api/v3/user
|
||||
* @转发路径 http://localhost:8080/user
|
||||
*/
|
||||
'/api/v3': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp('^/api'), ''),
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user