From 76036b9756c7d47b27c4ebf5c0bc4cfac6f85b8d Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Wed, 27 Mar 2019 19:42:22 -0400 Subject: [PATCH] fix(install): crash if mongodb failed to connect --- app.js | 25 ++++++++++--------------- src/controllers/install.js | 1 + src/install/mongotest.js | 10 +++++----- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index 642cfdf45..9d1d3683f 100644 --- a/app.js +++ b/app.js @@ -16,6 +16,8 @@ var path = require('path') var fs = require('fs') var winston = require('winston') var nconf = require('nconf') +var Chance = require('chance') +var chance = new Chance() var pkg = require('./package.json') // `var memory = require('./src/memory'); @@ -76,6 +78,14 @@ if (!process.env.FORK) { var configFile = path.join(__dirname, '/config.json') var configExists +nconf.defaults({ + base_dir: __dirname, + tokens: { + secret: chance.hash() + chance.md5(), + expires: 900 + } +}) + if (nconf.get('config')) { configFile = path.resolve(__dirname, nconf.get('config')) } @@ -97,10 +107,6 @@ function loadConfig () { nconf.file({ file: configFile }) - - nconf.defaults({ - base_dir: __dirname - }) } function start () { @@ -122,17 +128,6 @@ function start () { } function launchServer (db) { - var Chance = require('chance') - var chance = new Chance() - - if (!nconf.get('tokens')) { - nconf.set('tokens:secret', chance.hash() + chance.md5()) - nconf.set('tokens:expires', 900) - nconf.save(function (err) { - if (err) winston.warn(err) - }) - } - var ws = require('./src/webserver') ws.init(db, function (err) { if (err) { diff --git a/src/controllers/install.js b/src/controllers/install.js index 1666c2a8b..2ae398c19 100644 --- a/src/controllers/install.js +++ b/src/controllers/install.js @@ -51,6 +51,7 @@ installController.mongotest = function (req, res) { }) child.on('close', function () { + global.forks = _.without(global.forks, { name: 'mongotest' }) winston.debug('MongoTest process terminated') }) } diff --git a/src/install/mongotest.js b/src/install/mongotest.js index 840dbac52..4d0aee6e9 100644 --- a/src/install/mongotest.js +++ b/src/install/mongotest.js @@ -49,16 +49,16 @@ winston.add(winston.transports.Console, { database.init( function (e, db) { if (e) { - process.send({ error: e }) - return process.kill(0) + return process.send({ error: e }) + // return process.kill(0) } if (!db) { - process.send({ error: { message: 'Unable to open database' } }) - return process.kill(0) + return process.send({ error: { message: 'Unable to open database' } }) + // return process.kill(0) } - process.send({ success: true }) + return process.send({ success: true }) }, CONNECTION_URI, options