Skip to content

Commit

Permalink
fix(install): crash if mongodb failed to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Mar 27, 2019
1 parent b1f3452 commit 76036b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
25 changes: 10 additions & 15 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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'))
}
Expand All @@ -97,10 +107,6 @@ function loadConfig () {
nconf.file({
file: configFile
})

nconf.defaults({
base_dir: __dirname
})
}

function start () {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/controllers/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
}
Expand Down
10 changes: 5 additions & 5 deletions src/install/mongotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76036b9

Please sign in to comment.