-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 845 Bytes
/
index.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
'use strict'
const fastify = require('fastify')
const closeWithGrace = require('close-with-grace')
const config = require('./lib/config')
const logger = require('./lib/logger')(config.log)
const services = require('./app')
async function main () {
const app = fastify({ logger })
app.register(services(config))
const closeListeners = closeWithGrace({ delay: 500 }, async function ({ err }) {
if (err) {
app.log.error({ msg: 'error closing app', err })
}
await app.close()
app.log.info({ msg: 'app closed' })
})
app.addHook('onClose', (instance, done) => {
closeListeners.uninstall()
done()
})
try {
await app.listen({ port: config.app.port, host: '0.0.0.0' })
logger.info('ready!')
} catch (err) {
app.log.fatal({ msg: 'error starting app', err })
process.exit(1)
}
}
main()