diff --git a/src/app.ts b/src/app.ts index 263c9c9..5407c12 100644 --- a/src/app.ts +++ b/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); + }); }); \ No newline at end of file