diff --git a/lib/server-impl.js b/lib/server-impl.js index 9b1a1d80ca..bb15b81d2b 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -28,14 +28,13 @@ function createApp(options) { const app = getApp(config); startMonitoring(options.serverMetrics, eventBus); - return new Promise(resolve => { - const server = app.listen( - { port: options.port, host: options.host }, - () => { - logger.info(`Unleash started on port ${server.address().port}`); - resolve({ app, server, eventBus }); - } - ); + const server = app.listen({ port: options.port, host: options.host }, () => + logger.info(`Unleash started on port ${server.address().port}`) + ); + + return new Promise((resolve, reject) => { + server.on('listening', () => resolve({ app, server, eventBus })); + server.on('error', reject); }); } @@ -44,8 +43,7 @@ function start(opts) { return migrator({ databaseUrl: options.databaseUrl }) .catch(err => logger.error('failed to migrate db', err)) - .then(() => createApp(options)) - .catch(err => logger.error('failed creating app', err)); + .then(() => createApp(options)); } module.exports = {