close server when exit

Handle the SIGINT signal (such as when the user presses Ctrl+C in the terminal) by first closing the server and then exiting the program.
このコミットが含まれているのは:
Neco86 2023-05-11 19:28:15 +08:00 committed by GitHub
コミット 242d079994
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 4AEE18F83AFDEB23
1個のファイルの変更7行の追加1行の削除

ファイルの表示

@ -60,6 +60,12 @@ router.get('/ask/stream', async (ctx) => {
app.use(router.routes());
app.listen(3000, () => {
const server = app.listen(3000, () => {
console.log("Now listening: 127.0.0.1:3000");
});
process.on('SIGINT', () => {
server.close(() => {
process.exit(0);
});
});