diff --git a/gm-server/app.ts b/gm-server/app.ts index eeb6e74a1..07016c2d6 100644 --- a/gm-server/app.ts +++ b/gm-server/app.ts @@ -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() { diff --git a/gm-server/config/config.default.ts b/gm-server/config/config.default.ts index ff9acf677..d7dbc62d2 100644 --- a/gm-server/config/config.default.ts +++ b/gm-server/config/config.default.ts @@ -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/') } } } diff --git a/gm-server/config/config.local.ts b/gm-server/config/config.local.ts index 74f26ea5a..edc5c5b2e 100644 --- a/gm-server/config/config.local.ts +++ b/gm-server/config/config.local.ts @@ -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/') } } }