feat(配置): gm-server的跳转改为查询数据库

This commit is contained in:
luying
2023-04-15 19:03:42 +08:00
parent cd2ca7ff19
commit 3ed86c9bbc
2 changed files with 27 additions and 32 deletions

View File

@@ -1,4 +1,30 @@
import { RegionModel } from '@db/Region';
import proxy from 'egg-http-proxy-middleware';
module.exports = proxy;
module.exports = () => {
return async function (ctx, next) {
if(!ctx.app.config.envToHost) {
let envToHost = new Map<string, string>();
let regions = await RegionModel.getAllRegion();
for(let { env, gmLink } of regions) {
envToHost.set(env, gmLink);
}
ctx.app.config.envToHost = envToHost;
}
let options = {};
for(let [env, domain] of ctx.app.config.envToHost) {
options[`/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/')
}
}
}
return proxy(options)(ctx, next);
};
};