Skip to content
Snippets Groups Projects
Commit 4f707671 authored by Lucendio's avatar Lucendio
Browse files

Introduce a more graceful way to shut down

parent 22c70cd2
No related branches found
No related tags found
No related merge requests found
const path = require( 'path' ); const path = require( 'path' );
const http = require( 'http' );
const express = require('express'); const express = require('express');
const cors = require('cors'); const cors = require('cors');
...@@ -44,15 +45,21 @@ app.use(errorRoutes); ...@@ -44,15 +45,21 @@ app.use(errorRoutes);
(async function main(){ (async function main(){
try{ try{
const server = http.createServer( app );
await new Promise( (__ful, rej__ )=>{ await new Promise( (__ful, rej__ )=>{
app.listen(port, function(){ server.listen(port, function(){
console.log( `ToDo server is up on port ${ port }`); console.log( `ToDo server is up on port ${ port }`);
__ful(); __ful();
}).on( 'error', rej__); }).on( 'error', rej__);
}); });
process.on( 'SIGINT', ()=>{ process.on( 'SIGINT', async ()=>{
process.exit( 2 ); server.close( ()=>{
console.log( 'Shutting ToDo server' );
});
const dbClient = await dbClientInstance_;
await dbClient.disconnect();
process.exit( 0 );
}); });
}catch( err ){ }catch( err ){
console.error( err ); console.error( err );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment