后台:处理proxy

This commit is contained in:
luying
2021-12-30 15:28:08 +08:00
parent 4e63b109ae
commit 6e881bc9c7
3 changed files with 32 additions and 13 deletions
+13 -4
View File
@@ -24,19 +24,28 @@ export default (appInfo: EggAppInfo) => {
};
let regions = [ // 大区数据
{ id: 1, env: 'dev', name: "测试", domain: 'http://127.0.0.1:7002' },
{ id: 1, env: 'development', name: "测试", domain: 'http://127.0.0.1:7500' },
];
config.regions = regions;
let httpProxy: any = {};
for(let { env, domain } of regions) {
httpProxy[`/api/${env}`] = {
httpProxy[`/api/${env}/`] = {
target: domain,
changeOrigin: true,
secure: true,
pathRewrite: function(path) {
console.log('proxy', path, path.replace(`/api/${env}`, '/api'))
return path.replace(`/api/${env}`, '/api')
console.log('proxy', path, path.replace(`/api/${env}/`, '/api/'))
return path.replace(`/api/${env}/`, '/api/')
}
}
httpProxy[`/web/${env}/`] = {
target: domain,
changeOrigin: true,
secure: true,
pathRewrite: function(path) {
console.log('proxy', path, path.replace(`/web/${env}/`, '/web/'))
return path.replace(`/web/${env}/`, '/web/')
}
}
}