Skip to content

Node.js based forum software built for the modern web

closes #6378

Julian Lam741693bc1fa2
diff --git a/install/web.js b/install/web.js
index 8dbbeec278..3a6ad41aae 100644
--- a/install/web.js
+++ b/install/web.js
@@ -10,7 +10,6 @@ var less = require('less');
var async = require('async');
var uglify = require('uglify-js');
var nconf = require('nconf');
-var _ = require('lodash');
var Benchpress = require('benchpressjs');
var app = express();
@@ -56,7 +55,7 @@ web.install = function (port) {
extended: true,
}));
- async.parallel([compileLess, compileJS, copyCSS], function (err) {
+ async.parallel([compileLess, compileJS, copyCSS, loadDefaults], function (err) {
if (err) {
winston.error(err);
}
@@ -111,13 +110,24 @@ function welcome(req, res) {
function install(req, res) {
req.setTimeout(0);
- var setupEnvVars = _.assign({}, process.env);
+ var setupEnvVars = nconf.get();
for (var i in req.body) {
if (req.body.hasOwnProperty(i) && !process.env.hasOwnProperty(i)) {
setupEnvVars[i.replace(':', '__')] = req.body[i];
}
}
+ // Flatten any objects in setupEnvVars
+ const pushToRoot = function (parentKey, key) {
+ setupEnvVars[parentKey + '__' + key] = setupEnvVars[parentKey][key];
+ };
+ for (var j in setupEnvVars) {
+ if (setupEnvVars.hasOwnProperty(j) && typeof setupEnvVars[j] === 'object' && setupEnvVars[j] !== null) {
+ Object.keys(setupEnvVars[j]).forEach(pushToRoot.bind(null, j));
+ delete setupEnvVars[j];
+ }
+ }
+
var child = require('child_process').fork('app', ['--setup'], {
env: setupEnvVars,
});
@@ -137,15 +147,25 @@ function launch(req, res) {
res.json({});
server.close();
- var child = childProcess.spawn('node', ['loader.js'], {
- detached: true,
- stdio: ['ignore', 'ignore', 'ignore'],
- });
+ var child;
- console.log('\nStarting NodeBB');
- console.log(' "./nodebb stop" to stop the NodeBB server');
- console.log(' "./nodebb log" to view server output');
- console.log(' "./nodebb restart" to restart NodeBB');
+ if (!nconf.get('launchCmd')) {
+ child = childProcess.spawn('node', ['loader.js'], {
+ detached: true,
+ stdio: ['ignore', 'ignore', 'ignore'],
+ });
+
+ console.log('\nStarting NodeBB');
+ console.log(' "./nodebb stop" to stop the NodeBB server');
+ console.log(' "./nodebb log" to view server output');
+ console.log(' "./nodebb restart" to restart NodeBB');
+ } else {
+ // Use launchCmd instead, if specified
+ child = childProcess.exec(nconf.get('launchCmd'), {
+ detached: true,
+ stdio: ['ignore', 'ignore', 'ignore'],
+ });
+ }
var filesToDelete = [
'installer.css',
@@ -221,4 +241,20 @@ function copyCSS(next) {
], next);
}
+function loadDefaults(next) {
+ var setupDefaultsPath = path.join(__dirname, './data/setup.json');
+ fs.access(setupDefaultsPath, fs.constants.F_OK | fs.constants.R_OK, function (err) {
+ if (err) {
+ // setup.json not found or inaccessible, proceed with no defaults
+ return setImmediate(next);
+ }
+
+ nconf.file({
+ file: setupDefaultsPath,
+ });
+
+ next();
+ });
+}
+
module.exports = web;