-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
35 lines (28 loc) · 1.06 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require('dotenv').config()
const MongoClient = require('./app/database/client')
const App = require('./app/app')
const Server = App.listen(App.get('port'), () => {
console.log('Server port on port: ', App.get('port'))
})
const gracefulShutdown = () => {
Server.close((e) => {
console.log('Closing HTTP Server...')
MongoClient.calendarConn
.close()
.then(console.log("'Calendar' connection with MongoClient closed."))
.catch((e) => {
console.log("'Calendar' connection with MongoClient failed in an attempt to close. " + e)
})
MongoClient.usersConn
.close()
.then(console.log("'Users' connection with MongoClient closed."))
.catch((e) => {
console.log("'Users' connection with MongoClient failed in an attempt to close. " + e)
})
if (e) console.error(e)
process.exit(e ? 1 : 0)
})
}
process.on('SIGTERM', gracefulShutdown)
process.on('SIGINT', gracefulShutdown)
module.exports = { Server, App }