后台:处理proxy
This commit is contained in:
@@ -23,6 +23,14 @@ export default class FooBoot implements IBoot {
|
||||
if(this.app.config.env == 'local') {
|
||||
this.app.config.realEnv = 'development';
|
||||
}
|
||||
|
||||
// 如果gm使用的就是本机代理,host不转发到target而只把path替换
|
||||
if(this.app.config.httpProxy && this.app.config.httpProxy[`/web/${this.app.config.realEnv}/`]) {
|
||||
this.app.config.httpProxy[`/web/${this.app.config.realEnv}/`].changeOrigin = false;
|
||||
}
|
||||
if(this.app.config.httpProxy && this.app.config.httpProxy[`/api/${this.app.config.realEnv}/`]) {
|
||||
this.app.config.httpProxy[`/api/${this.app.config.realEnv}/`].changeOrigin = false;
|
||||
}
|
||||
}
|
||||
|
||||
configDidLoad() {
|
||||
|
||||
@@ -77,30 +77,32 @@ export default (appInfo: EggAppInfo) => {
|
||||
};
|
||||
|
||||
let regions = [ // 大区数据
|
||||
{ id: 1, env: 'stable', name: "常山少年", domain: 'http://zyz_gm.trgame.cn' },
|
||||
{ id: 2, env: 'alpha', name: "测试服", domain: 'http://pinus_gm_test.trgame.cn' },
|
||||
{ id: 3, env: 'dev', name: "开发服", domain: 'http://zyzdev_gm.trgame.cn' }
|
||||
{ env: 'stable', name: "常山少年", domain: 'http://zyz_gm.trgame.cn' },
|
||||
{ env: 'alpha', name: "测试服", domain: 'http://pinus_gm_test.trgame.cn' },
|
||||
{ env: 'dev', name: "开发服", domain: 'http://zyzdev_gm.trgame.cn' },
|
||||
// 37测试服组
|
||||
{ env: 'sq1', name: "37测试1服", domain: 'http://39.103.207.209: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}`] = {
|
||||
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')
|
||||
console.log('proxy', path, path.replace(`/web/${env}/`, '/web/'))
|
||||
return path.replace(`/web/${env}/`, '/web/')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user