mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-16 13:20:33 +00:00
fix: 热重载问题
This commit is contained in:
parent
36cdca5a3e
commit
95112d6bdf
@ -69,7 +69,7 @@ export abstract class HttpServerBase {
|
|||||||
// httpServerError = ""
|
// httpServerError = ""
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.close();
|
this.server.close();
|
||||||
this.server = null;
|
// this.server = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -258,64 +258,54 @@ export class NapCatOnebot11 {
|
|||||||
// if (!NewOb11 || typeof NewOb11 !== 'object') {
|
// if (!NewOb11 || typeof NewOb11 !== 'object') {
|
||||||
// throw new Error('Invalid configuration object');
|
// throw new Error('Invalid configuration object');
|
||||||
// }
|
// }
|
||||||
|
const OldConfig = JSON.parse(JSON.stringify(ob11Config)); //进行深拷贝
|
||||||
|
ob11Config.save(NewOb11);//保存新配置
|
||||||
|
|
||||||
|
const isHttpChanged = !isEqual(NewOb11.http.port, OldConfig.http.port);
|
||||||
|
const isHttpEnableChanged = !isEqual(NewOb11.http.enable, OldConfig.http.enable);
|
||||||
|
|
||||||
const isHttpChanged = !isEqual(NewOb11.http.port, ob11Config.http.port) && NewOb11.http.enable;
|
// const isHttpPostChanged = !isEqual(NewOb11.http.postUrls, OldConfig.http.postUrls);
|
||||||
const isHttpEnableChanged = !isEqual(NewOb11.http.enable, ob11Config.http.enable);
|
// const isEnanleHttpPostChanged = !isEqual(NewOb11.http.enablePost, OldConfig.http.enablePost);
|
||||||
|
|
||||||
const isHttpPostChanged = !isEqual(NewOb11.http.postUrls, ob11Config.http.postUrls);
|
const isWsChanged = !isEqual(NewOb11.ws.port, OldConfig.ws.port);
|
||||||
const isEnanleHttpPostChanged = !isEqual(NewOb11.http.enablePost, ob11Config.http.enablePost);
|
const isEnableWsChanged = !isEqual(NewOb11.ws.enable, OldConfig.ws.enable);
|
||||||
|
|
||||||
const isWsChanged = !isEqual(NewOb11.ws.port, ob11Config.ws.port);
|
const isEnableWsReverseChanged = !isEqual(NewOb11.reverseWs.enable, OldConfig.reverseWs.enable);
|
||||||
const isEnableWsChanged = !isEqual(NewOb11.ws.enable, ob11Config.ws.enable);
|
const isWsReverseUrlsChanged = !isEqual(NewOb11.reverseWs.urls, OldConfig.reverseWs.urls);
|
||||||
|
|
||||||
const isEnableWsReverseChanged = !isEqual(NewOb11.reverseWs.enable, ob11Config.reverseWs.enable);
|
//const isEnableHeartBeatChanged = !isEqual(NewOb11.heartInterval, OldConfig.heartInterval);
|
||||||
const isWsReverseUrlsChanged = !isEqual(NewOb11.reverseWs.urls, ob11Config.reverseWs.urls);
|
|
||||||
|
|
||||||
const isEnableHeartBeatChanged = !isEqual(NewOb11.heartInterval, ob11Config.heartInterval);
|
|
||||||
// http重启逻辑
|
// http重启逻辑
|
||||||
if (isHttpChanged) {
|
console.log(isHttpEnableChanged, isHttpChanged, NewOb11.http.enable);
|
||||||
ob11HTTPServer.restart(NewOb11.http.port, NewOb11.http.host);
|
if ((isHttpEnableChanged || isHttpChanged) && NewOb11.http.enable) {
|
||||||
}
|
if (OldConfig.http.enable) {
|
||||||
|
|
||||||
if (isHttpEnableChanged) {
|
|
||||||
if (NewOb11.http.enable) {
|
|
||||||
ob11HTTPServer.start(NewOb11.http.port, NewOb11.http.host);
|
|
||||||
} else {
|
|
||||||
ob11HTTPServer.stop();
|
ob11HTTPServer.stop();
|
||||||
}
|
}
|
||||||
|
ob11HTTPServer.start(NewOb11.http.port, NewOb11.http.host);
|
||||||
|
} else if (isHttpEnableChanged && !NewOb11.http.enable) {
|
||||||
|
ob11HTTPServer.stop();
|
||||||
}
|
}
|
||||||
// http post重启逻辑
|
|
||||||
|
|
||||||
// if(isHttpPostChanged){
|
|
||||||
// logDebug('http post urls changed, restart http server');
|
|
||||||
// }
|
|
||||||
// if(isEnanleHttpPostChanged){
|
|
||||||
// logDebug('http post enable changed, restart http server');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ws重启逻辑
|
// ws重启逻辑
|
||||||
if (isWsChanged) {
|
if ((isEnableWsChanged || isWsChanged) && NewOb11.ws.enable) {
|
||||||
ob11WebsocketServer.restart(NewOb11.ws.port);
|
if (OldConfig.ws.enable) {
|
||||||
}
|
ob11HTTPServer.stop();
|
||||||
|
|
||||||
if (isEnableWsChanged) {
|
|
||||||
if (NewOb11.ws.enable) {
|
|
||||||
ob11WebsocketServer.start(NewOb11.ws.port, NewOb11.ws.host);
|
|
||||||
} else {
|
|
||||||
ob11WebsocketServer.stop();
|
|
||||||
}
|
}
|
||||||
|
ob11WebsocketServer.start(NewOb11.ws.port, NewOb11.ws.host);
|
||||||
|
} else if (isHttpEnableChanged && !NewOb11.http.enable) {
|
||||||
|
ob11WebsocketServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 反向ws重启逻辑
|
// 反向ws重启逻辑
|
||||||
if (isEnableWsReverseChanged) {
|
if ((isEnableWsReverseChanged || isWsReverseUrlsChanged) && NewOb11.reverseWs.enable) {
|
||||||
if (NewOb11.reverseWs.enable) {
|
if (OldConfig.reverseWs.enable) {
|
||||||
ob11ReverseWebsockets.start();
|
ob11HTTPServer.stop();
|
||||||
} else {
|
|
||||||
ob11ReverseWebsockets.stop();
|
|
||||||
}
|
}
|
||||||
|
ob11ReverseWebsockets.start();
|
||||||
|
} else if (isHttpEnableChanged && !NewOb11.http.enable) {
|
||||||
|
ob11WebsocketServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
ob11Config.save(NewOb11);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError('热重载配置失败', e);
|
logError('热重载配置失败', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user