Skip to content
Permalink
Browse files

fix(install): crash if mongodb failed to connect

  • Loading branch information...
polonel committed Mar 27, 2019
1 parent b1f3452 commit 76036b9756c7d47b27c4ebf5c0bc4cfac6f85b8d
Showing with 16 additions and 20 deletions.
  1. +10 −15 app.js
  2. +1 −0 src/controllers/install.js
  3. +5 −5 src/install/mongotest.js
25 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) {
@@ -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')
})
}
@@ -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

0 comments on commit 76036b9

Please sign in to comment.
You can’t perform that action at this time.