diff --git a/src/webserver.js b/src/webserver.js index bda0b4243..51cdd93fc 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -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() @@ -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) {