Fix so server doesn't close process on exit

This commit is contained in:
Jonatan Nilsson 2020-09-12 03:55:13 +00:00
parent 586da219d1
commit f2f7d9ef9d

View file

@ -7,6 +7,7 @@ import coremonitor from './core/coremonitor.mjs'
import onConnection from './routerio.mjs' import onConnection from './routerio.mjs'
export function run(config, db, log, core, http, port) { export function run(config, db, log, core, http, port) {
return new Promise(function(resolve, reject) {
const __dirname = path.dirname(fileURLToPath(import.meta.url)) const __dirname = path.dirname(fileURLToPath(import.meta.url))
const staticRoot = path.join(__dirname,'../public') const staticRoot = path.join(__dirname,'../public')
@ -71,11 +72,11 @@ export function run(config, db, log, core, http, port) {
server.listen(port, '0.0.0.0', function(err) { server.listen(port, '0.0.0.0', function(err) {
if (err) { if (err) {
log.fatal(err) return reject(err)
log.event.error('Error starting server: ' + err.message)
return process.exit(2)
} }
log.event.info(`Server is listening on ${port} serving files on ${staticRoot}`) log.event.info(`Server is listening on ${port} serving files on ${staticRoot}`)
log.info(`Server is listening on ${port} serving files on ${staticRoot}`) log.info(`Server is listening on ${port} serving files on ${staticRoot}`)
resolve()
})
}) })
} }