Skip to content

Commit

Permalink
feat: 收到停止信号时先断开连接
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Sep 15, 2024
1 parent ee0ef79 commit 83dd6b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const logAccess = (req: Request, res: Response) => {

export class Server {
private app;
private io: SocketIOServer;
public io: SocketIOServer;
private httpsServer: https.Server;
public db: SQLiteHelper;
protected files: File[];
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import got from "got";

function onStop(signal: string) {
server.db.close();
server.io.sockets.sockets.forEach(socket => {
socket.disconnect(true);
});
server.io.close();
console.log(`Received ${signal}. Shutting down...`);
process.exit(0);
}
Expand Down

0 comments on commit 83dd6b6

Please sign in to comment.