diff --git a/.travis.yml b/.travis.yml index 016a0553f9..1e025adb1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ services: - - redis-server + - redis-server before_install: - - npm i --production - - node app --setup="{\"base_url\":\"http://127.0.0.1\",\"port\":4567,\"use_port\":false,\"secret\":\"abcdef\",\"bind_address\":\"0.0.0.0\",\"database\":\"redis\",\"redis:host\":\"127.0.0.1\",\"redis:port\":6379,\"redis:password\":\"\",\"redis:database\":0,\"admin:username\":\"admin\",\"admin:email\":\"test@example.org\",\"admin:password\":\"abcdef\",\"admin:password:confirm\":\"abcdef\"}" --ci="{\"host\":\"127.0.0.1\",\"port\":6379,\"database\":0}" + - npm i --production + - node app --setup="{\"url\":\"http://127.0.0.1:4567/\",\"secret\":\"abcdef\",\"database\":\"redis\",\"redis:host\":\"127.0.0.1\",\"redis:port\":6379,\"redis:password\":\"\",\"redis:database\":0,\"admin:username\":\"admin\",\"admin:email\":\"test@example.org\",\"admin:password\":\"abcdef\",\"admin:password:confirm\":\"abcdef\"}" --ci="{\"host\":\"127.0.0.1\",\"port\":6379,\"database\":0}" language: node_js node_js: - - "0.11" - - "0.10" + - "0.11" + - "0.10" branches: - only: - - master \ No newline at end of file + only: + - master \ No newline at end of file diff --git a/app.js b/app.js index e253f03f75..0f7fdc5faf 100644 --- a/app.js +++ b/app.js @@ -110,7 +110,6 @@ function start() { // 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); // 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); diff --git a/package.json b/package.json index ba878033db..02ceb450d2 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,8 @@ "nodebb-plugin-mentions": "^0.7.0", "nodebb-plugin-soundpack-default": "~0.1.1", "nodebb-plugin-spam-be-gone": "^0.3.0", - "nodebb-theme-lavender": "~0.1.0", - "nodebb-theme-vanilla": "~0.1.0", + "nodebb-theme-lavender": "^0.2.0", + "nodebb-theme-vanilla": "^0.2.0", "nodebb-widget-essentials": "~0.2.0", "npm": "^2.1.4", "passport": "^0.2.1", diff --git a/src/controllers/categories.js b/src/controllers/categories.js index a9928015d8..49890ab6f7 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -251,6 +251,7 @@ categoriesController.get = function(req, res, next) { } } + data.breadcrumbs = res.locals.breadcrumbs; res.render('category', data); }); }; diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 6d21aacb68..5aae9774cb 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -253,6 +253,7 @@ topicsController.get = function(req, res, next) { } } + data.breadcrumbs = res.locals.breadcrumbs; res.render('topic', data); }); }; diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 3281b4fd08..de99d4ab5f 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -197,6 +197,58 @@ middleware.checkAccountPermissions = function(req, res, next) { }); }; +middleware.buildBreadcrumbs = function(req, res, next) { + var breadcrumbs = [], + findParents = function(cid) { + var currentCategory; + async.doWhilst(function(next) { + categories.getCategoryFields(currentCategory ? currentCategory.parentCid : cid, ['name', 'slug', 'parentCid'], function(err, data) { + if (err) { + return next(err); + } + + breadcrumbs.unshift({ + text: data.name, + url: nconf.get('relative_path') + '/category/' + data.slug + }); + + currentCategory = data; + next(); + }); + }, function() { + return !!currentCategory.parentCid && currentCategory.parentCid !== '0'; + }, function(err) { + if (err) { + winston.warn('[buildBreadcrumb] Could not build breadcrumbs: ' + err.message); + } + + // Home breadcrumb + translator.translate('[[global:home]]', meta.config.defaultLang || 'en_GB', function(translated) { + breadcrumbs.unshift({ + text: translated, + url: nconf.get('relative_path') + }); + + res.locals.breadcrumbs = breadcrumbs || []; + next(); + }); + }); + }; + + if (req.params.topic_id) { + topics.getTopicFields(parseInt(req.params.topic_id, 10), ['cid', 'title', 'slug'], function(err, data) { + breadcrumbs.unshift({ + text: data.title, + url: nconf.get('relative_path') + '/topic/' + data.slug + }); + + findParents(parseInt(data.cid, 10)); + }); + } else { + findParents(parseInt(req.params.category_id, 10)); + } +}; + middleware.buildHeader = function(req, res, next) { res.locals.renderHeader = true; @@ -438,6 +490,9 @@ middleware.addExpiresHeaders = function(req, res, next) { if (app.enabled('cache')) { res.setHeader("Cache-Control", "public, max-age=5184000"); res.setHeader("Expires", new Date(Date.now() + 5184000000).toUTCString()); + } else { + res.setHeader("Cache-Control", "public, max-age=0"); + res.setHeader("Expires", new Date().toUTCString()); } next(); diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 9810d0a45d..560ae195bb 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -241,7 +241,7 @@ return res.status(400).send(err.message); } - res.status(200).send(nconf.get('relative_path') + (data.referrer ? data.referrer : '/')); + res.status(200).send(data.referrer ? data.referrer : '/'); }); } diff --git a/src/routes/index.js b/src/routes/index.js index ba5062e89d..ff1d4f0eab 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -40,8 +40,8 @@ function staticRoutes(app, middleware, controllers) { function topicRoutes(app, middleware, controllers) { app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser); - setupPageRoute(app, '/topic/:topic_id/:slug/:post_index?', middleware, [], controllers.topics.get); - setupPageRoute(app, '/topic/:topic_id/:slug?', middleware, [middleware.addSlug], controllers.topics.get); + setupPageRoute(app, '/topic/:topic_id/:slug/:post_index?', middleware, [middleware.buildBreadcrumbs], controllers.topics.get); + setupPageRoute(app, '/topic/:topic_id/:slug?', middleware, [middleware.buildBreadcrumbs, middleware.addSlug], controllers.topics.get); } function tagRoutes(app, middleware, controllers) { @@ -55,8 +55,8 @@ function categoryRoutes(app, middleware, controllers) { setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread); app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal); - setupPageRoute(app, '/category/:category_id/:slug/:topic_index', middleware, [], controllers.categories.get); - setupPageRoute(app, '/category/:category_id/:slug?', middleware, [middleware.addSlug], controllers.categories.get); + setupPageRoute(app, '/category/:category_id/:slug/:topic_index', middleware, [middleware.buildBreadcrumbs], controllers.categories.get); + setupPageRoute(app, '/category/:category_id/:slug?', middleware, [middleware.buildBreadcrumbs, middleware.addSlug], controllers.categories.get); } function accountRoutes(app, middleware, controllers) { diff --git a/src/upgrade.js b/src/upgrade.js index 1371af5927..9ff03a3e97 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -314,11 +314,25 @@ Upgrade.upgrade = function(callback) { function(config, next) { try { config = JSON.parse(config); + + // If the config contains "url", it has already been updated, abort. + if (config.hasOwnProperty('url')) { + return next(); + } + config.url = config.base_url + (config.use_port ? ':' + config.port : '') + config.relative_path; - if (config.port == '4567') delete config.port; - if (config.bcrypt_rounds == 12) delete config.bcrypt_rounds; - if (config.upload_path === '/public/uploads') delete config.upload_path; - if (config.bind_address === '0.0.0.0') delete config.bind_address; + if (config.port == '4567') { + delete config.port; + } + if (config.bcrypt_rounds == 12) { + delete config.bcrypt_rounds; + } + if (config.upload_path === '/public/uploads') { + delete config.upload_path; + } + if (config.bind_address === '0.0.0.0') { + delete config.bind_address; + } delete config.base_url; delete config.use_port; delete config.relative_path; diff --git a/src/user.js b/src/user.js index 6651fb8447..20e2fc69f3 100644 --- a/src/user.js +++ b/src/user.js @@ -272,7 +272,7 @@ var async = require('async'), return callback(null, password); } - Password.hash(nconf.get('bcrypt_rounds'), password, callback); + Password.hash(nconf.get('bcrypt_rounds') || 12, password, callback); }; User.addTopicIdToUser = function(uid, tid, timestamp, callback) { diff --git a/tests/mocks/databasemock.js b/tests/mocks/databasemock.js index ebb0c3df20..e694a9c9ba 100644 --- a/tests/mocks/databasemock.js +++ b/tests/mocks/databasemock.js @@ -19,7 +19,8 @@ base_dir: path.join(__dirname,'../..'), themes_path: path.join(__dirname, '../../node_modules'), upload_url: path.join(path.sep, '../../uploads', path.sep), - views_dir: path.join(__dirname, '../../public/templates') + views_dir: path.join(__dirname, '../../public/templates'), + relative_path: '' }); var dbType = nconf.get('database'),