diff --git a/backend/src/app.ts b/backend/src/app.ts index 260106c..b690eb0 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -52,14 +52,10 @@ class App { } } - public stop() { - whyIsNodeRunning() - this.database.disconnect(); - this.github.disconnect(); - this.eListener?.close(() => { - logger.info('Server closed'); - process.exit(0); - }); + public async stop() { + await new Promise(resolve => this.eListener?.close(resolve)); + await this.database.disconnect(); + await this.github.disconnect(); } private setupExpress() { @@ -78,15 +74,17 @@ class App { const __dirname = dirname(__filename); const frontendPath = path.resolve(__dirname, '../../frontend/dist/github-value/browser'); this.e.use(express.static(frontendPath)); - this.e.get('*', rateLimit({ - windowMs: 15 * 60 * 1000, max: 5000, - }), (_, res) => res.sendFile(path.join(frontendPath, 'index.html'))); + this.e.get( + '*', + rateLimit({ + windowMs: 15 * 60 * 1000, max: 5000, + }), + (_, res) => res.sendFile(path.join(frontendPath, 'index.html')) + ); - const listener = this.e.listen(this.port, () => { - const address = listener.address() as AddressInfo; - logger.info(`Server is running at http://${address.address === '::' ? 'localhost' : address.address}:${address.port} 🚀`); - }); - this.eListener = listener; + this.eListener = this.e.listen(this.port, () => { + logger.info(`Server is running 🚀`); + });; } private initializeSettings() { @@ -162,9 +160,10 @@ logger.info('App started'); export default app; ['SIGTERM', 'SIGINT', 'SIGQUIT'].forEach(signal => { - process.on(signal, () => { + process.on(signal, async () => { logger.info(`Received ${signal}. Stopping the app...`); - app.stop(); - process.exit(signal === 'uncaughtException' ? 1 : 0); + await app.stop(); + whyIsNodeRunning() + process.exit(0); }); }); diff --git a/backend/src/database.ts b/backend/src/database.ts index b9c28e4..f3970ec 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -101,9 +101,9 @@ class Database { } } - disconnect() { - this.sequelize?.connectionManager.close(); - this.sequelize?.close(); + async disconnect() { + await this.sequelize?.connectionManager.close(); + await this.sequelize?.close(); } initializeModels(sequelize: Sequelize) { diff --git a/backend/src/services/logger.ts b/backend/src/services/logger.ts index d460a20..1133291 100644 --- a/backend/src/services/logger.ts +++ b/backend/src/services/logger.ts @@ -33,7 +33,7 @@ const logger = bunyan.createLogger({ }, streams: [ { - level: 'info', + level: 'debug', stream: process.stdout }, {