diff --git a/app.js b/app.js index 013ea287fc..70d9baa41e 100644 --- a/app.js +++ b/app.js @@ -80,7 +80,7 @@ if (!nconf.get('help') && !nconf.get('setup') && !nconf.get('install') && !nconf reset(); } else { displayHelp(); -}; +} function loadConfig() { nconf.file({ @@ -156,7 +156,7 @@ function start() { winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:'); winston.warn(' node app --upgrade'); winston.warn('To ignore this error (not recommended):'); - winston.warn(' node app --no-check-schema') + winston.warn(' node app --no-check-schema'); process.exit(); } }); diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 82a4c0d135..90666dc744 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -1,3 +1,5 @@ +"use strict"; + var categoriesController = {}, async = require('async'), qs = require('querystring'), @@ -154,7 +156,7 @@ categoriesController.get = function(req, res, next) { next(null, { header: null, topics: categoryData - }) + }); } ], function (err, data) { if (err) { @@ -185,13 +187,6 @@ categoriesController.get = function(req, res, next) { } res.render('category', data.topics); - /*translator.translate(templates['noscript/category'].parse(data.topics), function(translatedHTML) { - res.send( - data.header + - '\n\t' + - '\n\t' + app.create_route('category/' + category_url) + templates.footer - ); - });*/ }); }; diff --git a/src/meta.js b/src/meta.js index b8c12a0721..91ef0d6474 100644 --- a/src/meta.js +++ b/src/meta.js @@ -1,3 +1,5 @@ +"use strict"; + var fs = require('fs'), path = require('path'), async = require('async'), @@ -102,8 +104,9 @@ var fs = require('fs'), if (fs.existsSync(config)) { fs.readFile(config, function (err, file) { - if (err) return next(); - else { + if (err) { + return next(); + } else { var configObj = JSON.parse(file.toString()); next(err, configObj); } @@ -152,12 +155,12 @@ var fs = require('fs'), ], function(err) { callback(err); }); - break; + break; case 'bootswatch': themeData['theme:src'] = data.src; db.setObject('config', themeData, callback); - break; + break; } } }; @@ -212,7 +215,7 @@ var fs = require('fs'), if (subpage) { translator.translate('[[pages:user.' + subpage + ', ' + username + ']]', function(translated) { callback(null, translated); - }) + }); } else { callback(null, username); } @@ -271,7 +274,9 @@ var fs = require('fs'), } }); - Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); + Meta.js.scripts = jsPaths.filter(function(path) { + return path !== null; + }); if (process.env.NODE_ENV !== 'development') { callback(null, [ diff --git a/src/middleware/index.js b/src/middleware/index.js index 90e5cee1cd..371e04ae1b 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -1,3 +1,5 @@ +"use strict"; + var templates = require('./../../public/src/templates'), translator = require('./../../public/src/translator'), meta = require('./../meta'), @@ -7,7 +9,7 @@ var templates = require('./../../public/src/templates'), path = require('path'), fs = require('fs'), nconf = require('nconf'), - express = require('express') + express = require('express'), winston = require('winston'); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index cdb48f576a..6863310746 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -1,5 +1,18 @@ +"use strict"; + + var app, - middleware = {}; + clientScripts, + middleware = {}, + async = require('async'), + path = require('path'), + validator = require('validator'), + fs = require('fs'), + nconf = require('nconf'), + plugins = require('./../plugins'), + meta = require('./../meta'), + translator = require('./../../public/src/translator'), + user = require('./../user'); middleware.prepareAPI = function(req, res, next) { res.locals.isAPI = true; @@ -216,7 +229,7 @@ middleware.build_header = function (options, callback) { callback(null, template); });*/ app.render('header', templateValues, function(err, template) { - callback(null, template) + callback(null, template); }); }); }); @@ -238,11 +251,11 @@ middleware.processRender = function(req, res, next) { self.send(str); }; - if ('function' == typeof options) { + if ('function' === typeof options) { fn = options, options = {}; } - if ('function' != typeof fn) { + if ('function' !== typeof fn) { fn = defaultFn; } @@ -276,9 +289,23 @@ middleware.routeTouchIcon = function(req, res) { maxAge: app.enabled('cache') ? 5184000000 : 0 }); } -} +}; module.exports = function(webserver) { app = webserver; + + plugins.ready(function() { + // Minify client-side libraries + meta.js.get(function (err, scripts) { + clientScripts = scripts.map(function (script) { + script = { + script: script + }; + + return script; + }); + }); + }); + return middleware; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/routes/authentication.js b/src/routes/authentication.js index f72836caf2..6fba7c3b92 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -1,4 +1,6 @@ (function(Auth) { + "use strict"; + var passport = require('passport'), passportLocal = require('passport-local').Strategy, nconf = require('nconf'), @@ -26,16 +28,16 @@ Auth.initialize = function(app) { app.use(passport.initialize()); app.use(passport.session()); - } + }; Auth.get_login_strategies = function() { return login_strategies; - } + }; Auth.registerApp = function(app) { Auth.app = app; - } + }; Auth.createRoutes = function(app) { app.namespace(nconf.get('relative_path'), function () { @@ -49,19 +51,21 @@ req.logout(); } - res.send(200) + res.send(200); }); for (var i in login_strategies) { - var strategy = login_strategies[i]; - app.get(strategy.url, passport.authenticate(strategy.name, { - scope: strategy.scope - })); - - app.get(strategy.callbackURL, passport.authenticate(strategy.name, { - successRedirect: '/', - failureRedirect: '/login' - })); + if (login_strategies.hasOwnProperty(i)) { + var strategy = login_strategies[i]; + app.get(strategy.url, passport.authenticate(strategy.name, { + scope: strategy.scope + })); + + app.get(strategy.callbackURL, passport.authenticate(strategy.name, { + successRedirect: '/', + failureRedirect: '/login' + })); + } } app.get('/reset/:code', function(req, res) { @@ -69,7 +73,7 @@ req: req, res: res }, function(err, header) { - res.send(header + app.create_route('reset/' + req.params.code) + templates['footer']); + res.send(header + app.create_route('reset/' + req.params.code) + templates.footer); }); }); @@ -78,7 +82,7 @@ req: req, res: res }, function(err, header) { - res.send(header + app.create_route('reset') + templates['footer']); + res.send(header + app.create_route('reset') + templates.footer); }); }); @@ -127,10 +131,11 @@ require('../socket.io').emitUserCount(); - if(req.body.referrer) + if(req.body.referrer) { res.redirect(req.body.referrer); - else + } else { res.redirect(nconf.get('relative_path') + '/'); + } }); } else { res.redirect(nconf.get('relative_path') + '/register'); @@ -138,7 +143,7 @@ }); }); }); - } + }; Auth.login = function(username, password, next) { if (!username || !password) { @@ -186,7 +191,7 @@ }); }); }); - } + }; passport.use(new passportLocal(Auth.login)); diff --git a/src/routes/index.js b/src/routes/index.js index 09e5de7415..d61aaec5fd 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,5 +1,8 @@ +"use strict"; + var nconf = require('nconf'), controllers = require('./../controllers'), + meta = require('./../meta'), middleware = {}, /*temp*/ @@ -152,7 +155,7 @@ module.exports = function(app, middleware) { req: req, res: res }, function (err, header) { - res.send(header + app.create_route('search/' + req.params.term, null, 'search') + templates.footer); + //res.send(header + app.create_route('search/' + req.params.term, null, 'search') + templates.footer); }); }); @@ -178,8 +181,10 @@ module.exports = function(app, middleware) { plugins.ready(function() { plugins.fireHook('filter:server.create_routes', custom_routes, function(err, custom_routes) { - var routes = custom_routes.routes; - for (var route in routes) { + var route, + routes = custom_routes.routes; + + for (route in routes) { if (routes.hasOwnProperty(route)) { (function(route) { app[routes[route].method || 'get'](routes[route].route, function(req, res) { @@ -188,7 +193,7 @@ module.exports = function(app, middleware) { req: options.req || req, res: options.res || res }, function (err, header) { - res.send(header + options.content + templates.footer); + //res.send(header + options.content + templates.footer); }); }); }); @@ -197,7 +202,7 @@ module.exports = function(app, middleware) { } var apiRoutes = custom_routes.api; - for (var route in apiRoutes) { + for (route in apiRoutes) { if (apiRoutes.hasOwnProperty(route)) { (function(route) { app[apiRoutes[route].method || 'get']('/api' + apiRoutes[route].route, function(req, res) { @@ -210,7 +215,7 @@ module.exports = function(app, middleware) { } var templateRoutes = custom_routes.templates; - for (var route in templateRoutes) { + for (route in templateRoutes) { if (templateRoutes.hasOwnProperty(route)) { (function(route) { app.get('/templates/' + templateRoutes[route].template, function(req, res) { @@ -223,4 +228,4 @@ module.exports = function(app, middleware) { }); }); }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index 9c95473ab5..e0694804a5 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -40,21 +40,7 @@ if(nconf.get('ssl')) { (function (app) { "use strict"; - var clientScripts, - port = nconf.get('PORT') || nconf.get('port'); - - plugins.ready(function() { - // Minify client-side libraries - meta.js.get(function (err, scripts) { - clientScripts = scripts.map(function (script) { - script = { - script: script - }; - - return script; - }); - }); - }); + var port = nconf.get('PORT') || nconf.get('port'); logger.init(app); auth.registerApp(app); @@ -97,12 +83,12 @@ if(nconf.get('ssl')) { }); } - if (port != 80 && port != 443 && nconf.get('use_port') === false) { + if (port !== 80 && port !== 443 && nconf.get('use_port') === false) { winston.info('Enabling \'trust proxy\''); app.enable('trust proxy'); } - if ((port == 80 || port == 443) && process.env.NODE_ENV !== 'development') { + if ((port === 80 || port === 443) && process.env.NODE_ENV !== 'development') { winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md'); }