diff --git a/src/database/db.ts b/src/database/db.ts index d26acbe..090b924 100644 --- a/src/database/db.ts +++ b/src/database/db.ts @@ -1,4 +1,5 @@ import knex from 'knex'; import knexConfig from './knexfile'; +export { redis } from './redis'; export const db = knex(knexConfig); diff --git a/src/server.ts b/src/server.ts index b23ce5c..6233936 100644 --- a/src/server.ts +++ b/src/server.ts @@ -2,6 +2,7 @@ import { app } from './app'; import { Server } from 'http'; import { AddressInfo } from 'net'; import { appConfig } from './config'; +import { db, redis } from './database/db'; const server: Server = app.listen(appConfig.port); @@ -37,8 +38,24 @@ server.on('error', (error: NodeJS.ErrnoException) => { function gracefulShutdown(signal: string): void { console.info(`Received ${signal}, shutting down gracefully.`); - server.close(() => { + server.close(async () => { console.info('HTTP server closed.'); + + try { + redis.quit(); + console.info('Redis connection closed.'); + } catch (error) { + console.error('Error closing Redis connection:', error); + } + + try { + await db.destroy(); + console.info('Database connection closed.'); + } catch (error) { + console.error('Error closing database connection:', error); + } + + console.info('All connections closed successfully.'); process.exit(0); });