✨ feat(配置): gm-server的跳转改为查询数据库
This commit is contained in:
@@ -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);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user