make isPrimary and isCluster always booleans
they were strings when using ./nodebb start and boolean if they were in config.json and started with node app.js
v1.18.x
Barış Soner Uşaklı 5 years ago
parent 8853cd1aa5
commit c2ca02dfc7

@ -308,7 +308,7 @@ postgresModule.createSessionStore = function (options, callback) {
const store = new sessionStore({
pool: db,
ttl: meta.getSessionTTLSeconds(),
pruneSessionInterval: nconf.get('isPrimary') === 'true' ? 60 : false,
pruneSessionInterval: nconf.get('isPrimary') ? 60 : false,
});
callback(null, store);
}
@ -317,7 +317,7 @@ postgresModule.createSessionStore = function (options, callback) {
if (err) {
return callback(err);
}
if (nconf.get('isPrimary') !== 'true') {
if (!nconf.get('isPrimary')) {
return done(db);
}
db.query(`

@ -38,7 +38,7 @@ Meta.userOrGroupExists = async function (slug) {
return userExists || groupExists;
};
if (nconf.get('isPrimary') === 'true') {
if (nconf.get('isPrimary')) {
pubsub.on('meta:restart', function (data) {
if (data.hostname !== os.hostname()) {
restart();

@ -116,7 +116,7 @@ Plugins.reload = async function () {
}
// If some plugins are incompatible, throw the warning here
if (Plugins.versionWarning.length && nconf.get('isPrimary') === 'true') {
if (Plugins.versionWarning.length && nconf.get('isPrimary')) {
console.log('');
winston.warn('[plugins/load] The following plugins may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing. In the event of an unresponsive NodeBB caused by this plugin, run `./nodebb reset -p PLUGINNAME` to disable it.');
for (var x = 0, numPlugins = Plugins.versionWarning.length; x < numPlugins; x += 1) {

@ -41,7 +41,7 @@ if (process.platform === 'win32') {
}
module.exports = function (Plugins) {
if (nconf.get('isPrimary') === 'true') {
if (nconf.get('isPrimary')) {
pubsub.on('plugins:toggleInstall', function (data) {
if (data.hostname !== os.hostname()) {
toggleInstall(data.id, data.version);

@ -54,14 +54,22 @@ function loadConfig(configFile) {
upload_path: 'public/uploads',
views_dir: path.join(dirname, 'build/public/templates'),
version: pkg.version,
isCluster: false,
isPrimary: true,
jobsDisabled: false,
});
if (!nconf.get('isCluster')) {
nconf.set('isPrimary', 'true');
nconf.set('isCluster', 'false');
}
var isPrimary = nconf.get('isPrimary');
nconf.set('isPrimary', isPrimary === undefined ? 'true' : isPrimary);
// Explicitly cast as Bool, loader.js passes in isCluster as string 'true'/'false'
var castAsBool = ['isCluster', 'isPrimary', 'jobsDisabled'];
nconf.stores.env.readOnly = false;
castAsBool.forEach(function (prop) {
var value = nconf.get(prop);
if (value !== undefined) {
nconf.set(prop, typeof value === 'boolean' ? value : String(value).toLowerCase() === 'true');
}
});
nconf.stores.env.readOnly = true;
nconf.set('runJobs', nconf.get('isPrimary') && !nconf.get('jobsDisabled'));
// Ensure themes_path is a full filepath
nconf.set('themes_path', path.resolve(dirname, nconf.get('themes_path')));
@ -71,18 +79,6 @@ function loadConfig(configFile) {
nconf.set('upload_path', path.resolve(nconf.get('base_dir'), nconf.get('upload_path')));
nconf.set('upload_url', '/assets/uploads');
// Explicitly cast 'jobsDisabled' as Bool
var castAsBool = ['jobsDisabled'];
nconf.stores.env.readOnly = false;
castAsBool.forEach(function (prop) {
var value = nconf.get(prop);
if (value) {
nconf.set(prop, typeof value === 'boolean' ? value : String(value).toLowerCase() === 'true');
}
});
nconf.stores.env.readOnly = true;
nconf.set('runJobs', nconf.get('isPrimary') === 'true' && !nconf.get('jobsDisabled'));
// nconf defaults, if not set in config
if (!nconf.get('sessionKey')) {

@ -14,7 +14,7 @@ function get() {
var pubsub;
if (nconf.get('isCluster') === 'false') {
if (!nconf.get('isCluster')) {
if (noCluster) {
real = noCluster;
return real;

@ -27,12 +27,14 @@ Sockets.init = function (server) {
path: nconf.get('relative_path') + '/socket.io',
});
if (nconf.get('singleHostCluster')) {
io.adapter(require('./single-host-cluster'));
} else if (nconf.get('redis')) {
io.adapter(require('../database/redis').socketAdapter());
} else {
io.adapter(db.socketAdapter());
if (nconf.get('isCluster')) {
if (nconf.get('singleHostCluster')) {
io.adapter(require('./single-host-cluster'));
} else if (nconf.get('redis')) {
io.adapter(require('../database/redis').socketAdapter());
} else {
io.adapter(db.socketAdapter());
}
}
io.use(socketioWildcard);

@ -79,7 +79,7 @@ async function runUpgrades() {
}
function printStartupInfo() {
if (nconf.get('isPrimary') === 'true') {
if (nconf.get('isPrimary')) {
winston.info('Initializing NodeBB v%s %s', nconf.get('version'), nconf.get('url'));
const host = nconf.get(nconf.get('database') + ':host');

@ -39,9 +39,9 @@ const urlObject = url.parse(nconf.get('url'));
const relativePath = urlObject.pathname !== '/' ? urlObject.pathname : '';
nconf.set('relative_path', relativePath);
if (!nconf.get('isCluster')) {
nconf.set('isPrimary', 'true');
nconf.set('isCluster', 'true');
if (nconf.get('isCluster') === undefined) {
nconf.set('isPrimary', true);
nconf.set('isCluster', true);
}
const dbType = nconf.get('database');

@ -8,7 +8,7 @@ var pubsub = require('../src/pubsub');
describe('pubsub', function () {
it('should use the plain event emitter', function (done) {
nconf.set('isCluster', 'false');
nconf.set('isCluster', false);
pubsub.reset();
pubsub.on('testEvent', function (message) {
assert.equal(message.foo, 1);
@ -21,7 +21,7 @@ describe('pubsub', function () {
it('should use same event emitter', function (done) {
pubsub.on('dummyEvent', function (message) {
assert.equal(message.foo, 2);
nconf.set('isCluster', 'true');
nconf.set('isCluster', true);
pubsub.removeAllListeners('dummyEvent');
pubsub.reset();
done();

Loading…
Cancel
Save