mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 15:42:52 +01:00
closes #6378
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user