diff --git a/app.js b/app.js index 768ac48c64..330ffc455c 100644 --- a/app.js +++ b/app.js @@ -25,6 +25,7 @@ nconf.argv().env(); var fs = require('fs'), os = require('os'), + url = require('url'), async = require('async'), semver = require('semver'), winston = require('winston'), @@ -107,6 +108,10 @@ function loadConfig() { function start() { loadConfig(); + // nconf defaults, if not set in config + if (!nconf.get('upload_path')) nconf.set('upload_path', '/public/uploads'); + if (!nconf.get('bcrypt_rounds')) nconf.set('bcrypt_rounds', 12); + if (!cluster.isWorker || process.env.cluster_setup === 'true') { winston.info('Time: %s', (new Date()).toString()); winston.info('Initializing NodeBB v%s', pkg.version); @@ -140,7 +145,10 @@ function start() { if (schema_ok || nconf.get('check-schema') === false) { sockets.init(webserver.server); - nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path')); + // Parse out the relative_url and other goodies from the configured URL + var urlObject = url.parse(nconf.get('url')); + nconf.set('use_port', !!urlObject.port); + nconf.set('relative_path', urlObject.pathname); async.waterfall([ async.apply(plugins.ready), diff --git a/src/install.js b/src/install.js index 564f06f703..db6bf09673 100644 --- a/src/install.js +++ b/src/install.js @@ -2,7 +2,6 @@ var async = require('async'), fs = require('fs'), - url = require('url'), path = require('path'), prompt = require('prompt'), winston = require('winston'), @@ -24,19 +23,15 @@ var install = {}, questions.main = [ { - name: 'base_url', + name: 'url', description: 'URL used to access this NodeBB', - 'default': nconf.get('base_url') ? (nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '')) : 'http://localhost:4567', + 'default': + nconf.get('url') || + (nconf.get('base_url') ? (nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '')) : null) || // backwards compatibility (remove for v0.7.0) + 'http://localhost:4567', pattern: /^http(?:s)?:\/\//, message: 'Base URL must begin with \'http://\' or \'https://\'', }, - { - name: 'port', - description: 'Port number of your NodeBB', - 'default': nconf.get('port') || 4567, - pattern: /[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]/, - message: 'Please enter a value betweeen 1 and 65535' - }, { name: 'secret', description: 'Please enter a NodeBB secret', @@ -175,6 +170,7 @@ function completeConfigSetup(err, config, next) { if (err) { return next(err); } + // Add CI object if (install.ciVals) { config.test_database = {}; @@ -185,22 +181,12 @@ function completeConfigSetup(err, config, next) { } } - config.bcrypt_rounds = 12; - config.upload_path = '/public/uploads'; - - var urlObject = url.parse(config.base_url), - server_conf = config; - - server_conf.base_url = urlObject.protocol + '//' + urlObject.hostname; - server_conf.use_port = urlObject.port !== null ? true : false; - server_conf.relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : ''; - - install.save(server_conf, function(err) { + install.save(config, function(err) { if (err) { return next(err); } - setupDatabase(server_conf, next); + setupDatabase(config, next); }); } @@ -329,7 +315,6 @@ function createAdmin(callback) { return retryPassword(results); } - nconf.set('bcrypt_rounds', 12); User.create({username: results.username, password: results.password, email: results.email}, function (err, uid) { if (err) { winston.warn(err.message + ' Please try again.'); diff --git a/src/webserver.js b/src/webserver.js index bf8394cc54..503d49d392 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -34,7 +34,7 @@ if(nconf.get('ssl')) { (function (app) { "use strict"; - var port = nconf.get('PORT') || nconf.get('port'); + var port = nconf.get('port') || nconf.get('PORT') || 4567; logger.init(app); emailer.registerApp(app);