chore: safe exit for database connection on SIGINT
This commit is contained in:
parent
054cb6c017
commit
acde6e1bbb
12
src/app.ts
12
src/app.ts
@ -6,6 +6,7 @@ import express from "express";
|
||||
import engine from "ejs-mate";
|
||||
|
||||
import "@bot/bot";
|
||||
import prisma from "@server/prisma";
|
||||
import homeRouter from "@server/routers/home.router";
|
||||
import guildRouter from "@server/routers/guild.router";
|
||||
import { attachGuilds } from "@server/middleware/attachGuilds";
|
||||
@ -27,6 +28,15 @@ app.use("/", attachGuilds, homeRouter);
|
||||
const HOST = process.env.HOST || "localhost";
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.listen(PORT, () => {
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(`Server is listening on port http://${HOST}:${PORT}`);
|
||||
});
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
console.log("\nShutdown signal received...");
|
||||
|
||||
prisma.$disconnect();
|
||||
server.close(error => {
|
||||
process.exit(error ? 1 : 0);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user