🐞 fix(37回调): 服务器列表刷新

This commit is contained in:
luying
2022-11-09 17:01:10 +08:00
parent e442fa6e7c
commit d4f932ae4f

View File

@@ -13,14 +13,7 @@ module.exports = () => {
ctx.app.config.envToHost = envToHost;
}
if(!ctx.app.config.sidToHost) {
let envToHost = ctx.app.config.envToHost||new Map();
let sidToHost = new Map<string, string>();
let servers = await ServerlistModel.getAllServerList();
for(let { id, env } of servers) {
let webHost = envToHost.get(env);
sidToHost.set(id.toString(), webHost);
}
ctx.app.config.sidToHost = sidToHost;
await getNewHost(ctx);
}
let options = {};
@@ -39,11 +32,16 @@ module.exports = () => {
let url = getProxyUrl(ctx.request.url);
if(url) {
let sid = ctx.request.method == 'GET'? ctx.query.sid.toString(): ctx.request.body.sid.toString();
options[url] = {
target: ctx.app.config.sidToHost.get(sid),
changeOrigin: true,
secure: true,
headers: { "is-proxy": "true" }
if(!ctx.app.config.sidToHost) {
await getNewHost(sid);
}
if(!!ctx.app.config.sidToHost.get(sid)) {
options[url] = {
target: ctx.app.config.sidToHost.get(sid),
changeOrigin: true,
secure: true,
headers: { "is-proxy": "true" }
}
}
}
}
@@ -52,6 +50,17 @@ module.exports = () => {
};
};
async function getNewHost(ctx) {
let envToHost = ctx.app.config.envToHost||new Map();
let sidToHost = new Map<string, string>();
let servers = await ServerlistModel.getAllServerList();
for(let { id, env } of servers) {
let webHost = envToHost.get(env);
sidToHost.set(id.toString(), webHost);
}
ctx.app.config.sidToHost = sidToHost;
}
function getProxyUrl(url: string) {
const urls = [
'/cb/treatusername',