mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
fixed issue where meta was called before nconf loaded
This commit is contained in:
28
app.js
28
app.js
@@ -16,7 +16,7 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Configuration setup
|
// Configuration setup
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
pkg = require('./package.json');
|
pkg = require('./package.json'),
|
||||||
|
meta;
|
||||||
|
|
||||||
// Runtime environment
|
// Runtime environment
|
||||||
global.env = process.env.NODE_ENV || 'production';
|
global.env = process.env.NODE_ENV || 'production';
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed
|
// TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed
|
||||||
winston.err = function(err) {
|
winston.err = function (err) {
|
||||||
winston.error(err.stack);
|
winston.error(err.stack);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,13 +52,13 @@
|
|||||||
winston.info('This is free software, and you are welcome to redistribute it under certain conditions.');
|
winston.info('This is free software, and you are welcome to redistribute it under certain conditions.');
|
||||||
winston.info('');
|
winston.info('');
|
||||||
|
|
||||||
var meta = require('./src/meta.js');
|
|
||||||
|
|
||||||
if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) {
|
if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) {
|
||||||
// Load server-side config
|
// Load server-side configs
|
||||||
nconf.file({
|
nconf.file({
|
||||||
file: __dirname + '/config.json'
|
file: __dirname + '/config.json'
|
||||||
});
|
});
|
||||||
|
meta = require('./src/meta.js');
|
||||||
|
|
||||||
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
|
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
|
||||||
nconf.set('upload_url', nconf.get('url') + 'uploads/');
|
nconf.set('upload_url', nconf.get('url') + 'uploads/');
|
||||||
@@ -68,12 +69,12 @@
|
|||||||
winston.info('Base Configuration OK.');
|
winston.info('Base Configuration OK.');
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.configs.init(function() {
|
meta.configs.init(function () {
|
||||||
// Initial setup for Redis & Reds
|
// Initial setup for Redis & Reds
|
||||||
var reds = require('reds'),
|
var reds = require('reds'),
|
||||||
RDB = require('./src/redis.js');
|
RDB = require('./src/redis.js');
|
||||||
|
|
||||||
reds.createClient = function() {
|
reds.createClient = function () {
|
||||||
return reds.client || (reds.client = RDB);
|
return reds.client || (reds.client = RDB);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,19 +96,16 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
} else if (nconf.get('upgrade')) {
|
} else if (nconf.get('upgrade')) {
|
||||||
nconf.file({
|
meta = require('./src/meta.js');
|
||||||
file: __dirname + '/config.json'
|
|
||||||
});
|
|
||||||
|
|
||||||
meta.configs.init(function() {
|
meta.configs.init(function () {
|
||||||
require('./src/upgrade').upgrade();
|
require('./src/upgrade').upgrade();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// New install, ask setup questions
|
// New install, ask setup questions
|
||||||
if (nconf.get('setup')) {
|
if (nconf.get('setup')) {
|
||||||
winston.info('NodeBB Setup Triggered via Command Line');
|
winston.info('NodeBB Setup Triggered via Command Line');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
winston.warn('Configuration not found, starting NodeBB setup');
|
winston.warn('Configuration not found, starting NodeBB setup');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +115,7 @@
|
|||||||
winston.info('This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.');
|
winston.info('This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.');
|
||||||
winston.info('Press enter to accept the default setting (shown in brackets).');
|
winston.info('Press enter to accept the default setting (shown in brackets).');
|
||||||
|
|
||||||
install.setup(function(err) {
|
install.setup(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('There was a problem completing NodeBB setup: ', err.message);
|
winston.error('There was a problem completing NodeBB setup: ', err.message);
|
||||||
} else {
|
} else {
|
||||||
@@ -127,4 +125,4 @@
|
|||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|||||||
120
src/install.js
120
src/install.js
@@ -6,7 +6,7 @@ var async = require('async'),
|
|||||||
prompt = require('prompt'),
|
prompt = require('prompt'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
reds = require('reds'),
|
reds = require('reds'),
|
||||||
nconf = require('nconf');
|
nconf = require('nconf'),
|
||||||
|
|
||||||
install = {
|
install = {
|
||||||
questions: [{
|
questions: [{
|
||||||
@@ -41,16 +41,18 @@ var async = require('async'),
|
|||||||
name: 'redis:password',
|
name: 'redis:password',
|
||||||
description: 'Password of your Redis database'
|
description: 'Password of your Redis database'
|
||||||
}],
|
}],
|
||||||
setup: function(callback) {
|
setup: function (callback) {
|
||||||
async.series([
|
async.series([
|
||||||
function(next) {
|
function (next) {
|
||||||
// prompt prepends "prompt: " to questions, let's clear that.
|
// prompt prepends "prompt: " to questions, let's clear that.
|
||||||
prompt.start();
|
prompt.start();
|
||||||
prompt.message = '';
|
prompt.message = '';
|
||||||
prompt.delimiter = '';
|
prompt.delimiter = '';
|
||||||
|
|
||||||
prompt.get(install.questions, function(err, config) {
|
prompt.get(install.questions, function (err, config) {
|
||||||
if (!config) return next(new Error('aborted'));
|
if (!config) {
|
||||||
|
return next(new Error('aborted'));
|
||||||
|
}
|
||||||
|
|
||||||
// Translate redis properties into redis object
|
// Translate redis properties into redis object
|
||||||
config.redis = {
|
config.redis = {
|
||||||
@@ -63,9 +65,9 @@ var async = require('async'),
|
|||||||
delete config['redis:password'];
|
delete config['redis:password'];
|
||||||
|
|
||||||
// Add hardcoded values
|
// Add hardcoded values
|
||||||
config['bcrypt_rounds'] = 12,
|
config.bcrypt_rounds = 12;
|
||||||
config['upload_path'] = '/public/uploads';
|
config.upload_path = '/public/uploads';
|
||||||
config['use_port'] = (config['use_port'].slice(0, 1) === 'y') ? true : false;
|
config.use_port = (config.use_port.slice(0, 1) === 'y') ? true : false;
|
||||||
|
|
||||||
var urlObject = url.parse(config.base_url),
|
var urlObject = url.parse(config.base_url),
|
||||||
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
|
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
|
||||||
@@ -86,9 +88,9 @@ var async = require('async'),
|
|||||||
install.save(server_conf, client_conf, next);
|
install.save(server_conf, client_conf, next);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function (next) {
|
||||||
// Applying default database configs
|
// Applying default database configs
|
||||||
winston.info('Populating database with default configs, if not already set...')
|
winston.info('Populating database with default configs, if not already set...');
|
||||||
var meta = require('./meta'),
|
var meta = require('./meta'),
|
||||||
defaults = [{
|
defaults = [{
|
||||||
field: 'postDelay',
|
field: 'postDelay',
|
||||||
@@ -113,48 +115,57 @@ var async = require('async'),
|
|||||||
value: ''
|
value: ''
|
||||||
}];
|
}];
|
||||||
|
|
||||||
async.each(defaults, function(configObj, next) {
|
async.each(defaults, function (configObj, next) {
|
||||||
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
|
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
meta.configs.init(next);
|
meta.configs.init(next);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function (next) {
|
||||||
// Check if an administrator needs to be created
|
// Check if an administrator needs to be created
|
||||||
var Groups = require('./groups');
|
var Groups = require('./groups');
|
||||||
|
|
||||||
Groups.getGidFromName('Administrators', function(err, gid) {
|
Groups.getGidFromName('Administrators', function (err, gid) {
|
||||||
if (err) return next(err.message);
|
if (err) {
|
||||||
|
return next(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
if (gid) {
|
if (gid) {
|
||||||
Groups.get(gid, {}, function(err, groupObj) {
|
Groups.get(gid, {}, function (err, groupObj) {
|
||||||
if (groupObj.count > 0) {
|
if (groupObj.count > 0) {
|
||||||
winston.info('Administrator found, skipping Admin setup');
|
winston.info('Administrator found, skipping Admin setup');
|
||||||
next();
|
next();
|
||||||
} else install.createAdmin(next);
|
} else {
|
||||||
|
install.createAdmin(next);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else install.createAdmin(next);
|
} else {
|
||||||
|
install.createAdmin(next);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function (next) {
|
||||||
// Categories
|
// Categories
|
||||||
var Categories = require('./categories'),
|
var Categories = require('./categories'),
|
||||||
admin = {
|
admin = {
|
||||||
categories: require('./admin/categories')
|
categories: require('./admin/categories')
|
||||||
};
|
};
|
||||||
|
|
||||||
categories.getAllCategories(function(data) {
|
Categories.getAllCategories(function (data) {
|
||||||
if (data.categories.length === 0) {
|
if (data.categories.length === 0) {
|
||||||
winston.warn('No categories found, populating instance with default categories')
|
winston.warn('No categories found, populating instance with default categories');
|
||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function(err, default_categories) {
|
fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function (err, default_categories) {
|
||||||
default_categories = JSON.parse(default_categories);
|
default_categories = JSON.parse(default_categories);
|
||||||
|
|
||||||
async.eachSeries(default_categories, function(category, next) {
|
async.eachSeries(default_categories, function (category, next) {
|
||||||
admin.categories.create(category, next);
|
admin.categories.create(category, next);
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
if (!err) next();
|
if (!err) {
|
||||||
else winston.error('Could not set up categories');
|
next();
|
||||||
|
} else {
|
||||||
|
winston.error('Could not set up categories');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -163,7 +174,7 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function (next) {
|
||||||
// Default plugins
|
// Default plugins
|
||||||
var Plugins = require('./plugins');
|
var Plugins = require('./plugins');
|
||||||
|
|
||||||
@@ -173,24 +184,28 @@ var async = require('async'),
|
|||||||
'nodebb-plugin-markdown', 'nodebb-plugin-mentions'
|
'nodebb-plugin-markdown', 'nodebb-plugin-mentions'
|
||||||
];
|
];
|
||||||
|
|
||||||
async.each(defaultEnabled, function(pluginId, next) {
|
async.each(defaultEnabled, function (pluginId, next) {
|
||||||
Plugins.isActive(pluginId, function(err, active) {
|
Plugins.isActive(pluginId, function (err, active) {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
Plugins.toggleActive(pluginId, function() {
|
Plugins.toggleActive(pluginId, function () {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
} else next();
|
} else {
|
||||||
})
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
}, next);
|
}, next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.warn('NodeBB Setup Aborted.');
|
winston.warn('NodeBB Setup Aborted.');
|
||||||
process.exit();
|
process.exit();
|
||||||
} else callback();
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createAdmin: function(callback) {
|
createAdmin: function (callback) {
|
||||||
var User = require('./user'),
|
var User = require('./user'),
|
||||||
Groups = require('./groups');
|
Groups = require('./groups');
|
||||||
|
|
||||||
@@ -212,21 +227,24 @@ var async = require('async'),
|
|||||||
hidden: true,
|
hidden: true,
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}],
|
}],
|
||||||
getAdminInfo = function(callback) {
|
getAdminInfo = function (callback) {
|
||||||
prompt.get(questions, function(err, results) {
|
prompt.get(questions, function (err, results) {
|
||||||
if (!results) return callback(new Error('aborted'));
|
if (!results) {
|
||||||
|
return callback(new Error('aborted'));
|
||||||
|
}
|
||||||
|
|
||||||
nconf.set('bcrypt_rounds', 12);
|
nconf.set('bcrypt_rounds', 12);
|
||||||
User.create(results.username, results.password, results.email, function(err, uid) {
|
User.create(results.username, results.password, results.email, function (err, uid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.warn(err.message + ' Please try again.');
|
winston.warn(err.message + ' Please try again.');
|
||||||
return getAdminInfo();
|
return getAdminInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
Groups.getGidFromName('Administrators', function(err, gid) {
|
Groups.getGidFromName('Administrators', function (err, gid) {
|
||||||
if (gid) Groups.join(gid, uid, callback);
|
if (gid) {
|
||||||
else {
|
Groups.join(gid, uid, callback);
|
||||||
Groups.create('Administrators', 'Forum Administrators', function(err, groupObj) {
|
} else {
|
||||||
|
Groups.create('Administrators', 'Forum Administrators', function (err, groupObj) {
|
||||||
Groups.join(groupObj.gid, uid, callback);
|
Groups.join(groupObj.gid, uid, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -237,20 +255,20 @@ var async = require('async'),
|
|||||||
|
|
||||||
getAdminInfo(callback);
|
getAdminInfo(callback);
|
||||||
},
|
},
|
||||||
save: function(server_conf, client_conf, callback) {
|
save: function (server_conf, client_conf, callback) {
|
||||||
// Server Config
|
// Server Config
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function (next) {
|
||||||
fs.writeFile(path.join(__dirname, '../', 'config.json'), JSON.stringify(server_conf, null, 4), function(err) {
|
fs.writeFile(path.join(__dirname, '../', 'config.json'), JSON.stringify(server_conf, null, 4), function (err) {
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function (next) {
|
||||||
fs.writeFile(path.join(__dirname, '../', 'public', 'config.json'), JSON.stringify(client_conf, null, 4), function(err) {
|
fs.writeFile(path.join(__dirname, '../', 'public', 'config.json'), JSON.stringify(client_conf, null, 4), function (err) {
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function (err) {
|
||||||
winston.info('Configuration Saved OK');
|
winston.info('Configuration Saved OK');
|
||||||
|
|
||||||
nconf.file({
|
nconf.file({
|
||||||
@@ -258,9 +276,9 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
|
|
||||||
var RDB = require('./redis');
|
var RDB = require('./redis');
|
||||||
reds.createClient = function() {
|
reds.createClient = function () {
|
||||||
return reds.client || (reds.client = RDB);
|
return reds.client || (reds.client = RDB);
|
||||||
}
|
};
|
||||||
|
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user