Skip to content

Commit

Permalink
chore(webserver): server listens just before ready event
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Feb 15, 2019
1 parent 9bfdb15 commit 50eeda2
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Copyright (c) 2014-2019. All rights reserved.
*/

var _ = require('lodash')
var async = require('async')
var express = require('express')
var WebServer = express()
Expand Down Expand Up @@ -60,24 +61,29 @@ var port = process.env.PORT || 8118
}
],
function () {
server.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
winston.error('Address in use, exiting...')
server.close()
} else {
winston.error(err.message)
throw err
}
})
return callback()
}
)
}

server.listen(port, '0.0.0.0', function () {
global.TRUDESK_PORT = port
winston.info('TruDesk is now listening on port: ' + port)
module.exports.listen = function (callback, p) {
if (!_.isUndefined(p)) port = p

callback()
})
server.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
winston.error('Address in use, exiting...')
server.close()
} else {
winston.error(err.message)
throw err
}
)
})

server.listen(port, '0.0.0.0', function () {
winston.info('TruDesk is now listening on port: ' + port)

if (_.isFunction(callback)) return callback()
})
}

module.exports.installServer = function (callback) {
Expand Down

0 comments on commit 50eeda2

Please sign in to comment.