Skip to content

Commit

Permalink
optimize: log
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuchen committed Apr 27, 2024
1 parent c90ffbe commit 9748d99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/common/server/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ export abstract class HttpServerBase {

protected listen(port: number, host: string = '0.0.0.0') {
host = host || '0.0.0.0';
this.server = this.expressAPP.listen(port, host, () => {
const info = `${this.name} started ${host}:${port}`;
log(info);
});
try {
this.server = this.expressAPP.listen(port, host, () => {
const info = `${this.name} started ${host}:${port}`;
log(info);
});
}catch (e: any) {
logError('HTTP服务启动失败, 请检查监听的ip地址和端口', e.stack.toString());
}
}
}
2 changes: 1 addition & 1 deletion src/common/server/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class WebsocketServerBase {
});
log(`ws服务启动成功, ${host}:${port}`);
} catch (e: any) {
throw Error('ws服务启动失败, ' + e.toString());
throw Error('ws服务启动失败, 请检查监听的ip和端口' + e.toString());
}
this.ws.on('connection', (wsClient, req) => {
const url: string = req.url!.split('?').shift() || '/';
Expand Down
4 changes: 2 additions & 2 deletions src/onebot11/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export class NapCatOnebot11 {
logDebug('ob11 ready');
ob11Config.read();
const serviceInfo = `
HTTP服务 ${ob11Config.enableHttp ? '已启动' : '未启动'}, 端口: ${ob11Config.httpPort}
HTTP服务 ${ob11Config.enableHttp ? '已启动' : '未启动'}, ${ob11Config.httpHost}:${ob11Config.httpPort}
HTTP上报服务 ${ob11Config.enableHttpPost ? '已启动' : '未启动'}, 上报地址: ${ob11Config.httpPostUrls}
WebSocket服务 ${ob11Config.enableWs ? '已启动' : '未启动'}, 端口: ${ob11Config.wsPort}
WebSocket服务 ${ob11Config.enableWs ? '已启动' : '未启动'}, ${ob11Config.wsHost}:${ob11Config.wsPort}
WebSocket反向服务 ${ob11Config.enableWsReverse ? '已启动' : '未启动'}, 反向地址: ${ob11Config.wsReverseUrls}
`;
log(serviceInfo);
Expand Down
4 changes: 2 additions & 2 deletions src/onebot11/server/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class OB11HTTPServer extends HttpServerBase {
res.send(OB11Response.error(e.stack.toString(), 200));
}

protected listen(port: number) {
protected listen(port: number, host: string) {
if (ob11Config.enableHttp) {
super.listen(port);
super.listen(port, host);
}
}
}
Expand Down

0 comments on commit 9748d99

Please sign in to comment.