🐞 fix(37回调): 服务器列表刷新
This commit is contained in:
@@ -13,14 +13,7 @@ module.exports = () => {
|
|||||||
ctx.app.config.envToHost = envToHost;
|
ctx.app.config.envToHost = envToHost;
|
||||||
}
|
}
|
||||||
if(!ctx.app.config.sidToHost) {
|
if(!ctx.app.config.sidToHost) {
|
||||||
let envToHost = ctx.app.config.envToHost||new Map();
|
await getNewHost(ctx);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = {};
|
let options = {};
|
||||||
@@ -39,11 +32,16 @@ module.exports = () => {
|
|||||||
let url = getProxyUrl(ctx.request.url);
|
let url = getProxyUrl(ctx.request.url);
|
||||||
if(url) {
|
if(url) {
|
||||||
let sid = ctx.request.method == 'GET'? ctx.query.sid.toString(): ctx.request.body.sid.toString();
|
let sid = ctx.request.method == 'GET'? ctx.query.sid.toString(): ctx.request.body.sid.toString();
|
||||||
options[url] = {
|
if(!ctx.app.config.sidToHost) {
|
||||||
target: ctx.app.config.sidToHost.get(sid),
|
await getNewHost(sid);
|
||||||
changeOrigin: true,
|
}
|
||||||
secure: true,
|
if(!!ctx.app.config.sidToHost.get(sid)) {
|
||||||
headers: { "is-proxy": "true" }
|
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) {
|
function getProxyUrl(url: string) {
|
||||||
const urls = [
|
const urls = [
|
||||||
'/cb/treatusername',
|
'/cb/treatusername',
|
||||||
|
|||||||
Reference in New Issue
Block a user