random jshinting expedition

v1.18.x
psychobunny 11 years ago
parent f0dfee5402
commit 6820e9e662

@ -80,7 +80,7 @@ if (!nconf.get('help') && !nconf.get('setup') && !nconf.get('install') && !nconf
reset(); reset();
} else { } else {
displayHelp(); displayHelp();
}; }
function loadConfig() { function loadConfig() {
nconf.file({ 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('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(' node app --upgrade');
winston.warn('To ignore this error (not recommended):'); winston.warn('To ignore this error (not recommended):');
winston.warn(' node app --no-check-schema') winston.warn(' node app --no-check-schema');
process.exit(); process.exit();
} }
}); });

@ -1,3 +1,5 @@
"use strict";
var categoriesController = {}, var categoriesController = {},
async = require('async'), async = require('async'),
qs = require('querystring'), qs = require('querystring'),
@ -154,7 +156,7 @@ categoriesController.get = function(req, res, next) {
next(null, { next(null, {
header: null, header: null,
topics: categoryData topics: categoryData
}) });
} }
], function (err, data) { ], function (err, data) {
if (err) { if (err) {
@ -185,13 +187,6 @@ categoriesController.get = function(req, res, next) {
} }
res.render('category', data.topics); res.render('category', data.topics);
/*translator.translate(templates['noscript/category'].parse(data.topics), function(translatedHTML) {
res.send(
data.header +
'\n\t<noscript>\n' + templates['noscript/header'] + translatedHTML + '\n\t</noscript>' +
'\n\t' + app.create_route('category/' + category_url) + templates.footer
);
});*/
}); });
}; };

@ -1,3 +1,5 @@
"use strict";
var fs = require('fs'), var fs = require('fs'),
path = require('path'), path = require('path'),
async = require('async'), async = require('async'),
@ -102,8 +104,9 @@ var fs = require('fs'),
if (fs.existsSync(config)) { if (fs.existsSync(config)) {
fs.readFile(config, function (err, file) { fs.readFile(config, function (err, file) {
if (err) return next(); if (err) {
else { return next();
} else {
var configObj = JSON.parse(file.toString()); var configObj = JSON.parse(file.toString());
next(err, configObj); next(err, configObj);
} }
@ -152,12 +155,12 @@ var fs = require('fs'),
], function(err) { ], function(err) {
callback(err); callback(err);
}); });
break; break;
case 'bootswatch': case 'bootswatch':
themeData['theme:src'] = data.src; themeData['theme:src'] = data.src;
db.setObject('config', themeData, callback); db.setObject('config', themeData, callback);
break; break;
} }
} }
}; };
@ -212,7 +215,7 @@ var fs = require('fs'),
if (subpage) { if (subpage) {
translator.translate('[[pages:user.' + subpage + ', ' + username + ']]', function(translated) { translator.translate('[[pages:user.' + subpage + ', ' + username + ']]', function(translated) {
callback(null, translated); callback(null, translated);
}) });
} else { } else {
callback(null, username); 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') { if (process.env.NODE_ENV !== 'development') {
callback(null, [ callback(null, [

@ -1,3 +1,5 @@
"use strict";
var templates = require('./../../public/src/templates'), var templates = require('./../../public/src/templates'),
translator = require('./../../public/src/translator'), translator = require('./../../public/src/translator'),
meta = require('./../meta'), meta = require('./../meta'),
@ -7,7 +9,7 @@ var templates = require('./../../public/src/templates'),
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
nconf = require('nconf'), nconf = require('nconf'),
express = require('express') express = require('express'),
winston = require('winston'); winston = require('winston');

@ -1,5 +1,18 @@
"use strict";
var app, 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) { middleware.prepareAPI = function(req, res, next) {
res.locals.isAPI = true; res.locals.isAPI = true;
@ -216,7 +229,7 @@ middleware.build_header = function (options, callback) {
callback(null, template); callback(null, template);
});*/ });*/
app.render('header', templateValues, function(err, 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); self.send(str);
}; };
if ('function' == typeof options) { if ('function' === typeof options) {
fn = options, options = {}; fn = options, options = {};
} }
if ('function' != typeof fn) { if ('function' !== typeof fn) {
fn = defaultFn; fn = defaultFn;
} }
@ -276,9 +289,23 @@ middleware.routeTouchIcon = function(req, res) {
maxAge: app.enabled('cache') ? 5184000000 : 0 maxAge: app.enabled('cache') ? 5184000000 : 0
}); });
} }
} };
module.exports = function(webserver) { module.exports = function(webserver) {
app = 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; return middleware;
} };

@ -1,4 +1,6 @@
(function(Auth) { (function(Auth) {
"use strict";
var passport = require('passport'), var passport = require('passport'),
passportLocal = require('passport-local').Strategy, passportLocal = require('passport-local').Strategy,
nconf = require('nconf'), nconf = require('nconf'),
@ -26,16 +28,16 @@
Auth.initialize = function(app) { Auth.initialize = function(app) {
app.use(passport.initialize()); app.use(passport.initialize());
app.use(passport.session()); app.use(passport.session());
} };
Auth.get_login_strategies = function() { Auth.get_login_strategies = function() {
return login_strategies; return login_strategies;
} };
Auth.registerApp = function(app) { Auth.registerApp = function(app) {
Auth.app = app; Auth.app = app;
} };
Auth.createRoutes = function(app) { Auth.createRoutes = function(app) {
app.namespace(nconf.get('relative_path'), function () { app.namespace(nconf.get('relative_path'), function () {
@ -49,19 +51,21 @@
req.logout(); req.logout();
} }
res.send(200) res.send(200);
}); });
for (var i in login_strategies) { for (var i in login_strategies) {
var strategy = login_strategies[i]; if (login_strategies.hasOwnProperty(i)) {
app.get(strategy.url, passport.authenticate(strategy.name, { var strategy = login_strategies[i];
scope: strategy.scope app.get(strategy.url, passport.authenticate(strategy.name, {
})); scope: strategy.scope
}));
app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
successRedirect: '/', app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
failureRedirect: '/login' successRedirect: '/',
})); failureRedirect: '/login'
}));
}
} }
app.get('/reset/:code', function(req, res) { app.get('/reset/:code', function(req, res) {
@ -69,7 +73,7 @@
req: req, req: req,
res: res res: res
}, function(err, header) { }, 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, req: req,
res: res res: res
}, function(err, header) { }, 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(); require('../socket.io').emitUserCount();
if(req.body.referrer) if(req.body.referrer) {
res.redirect(req.body.referrer); res.redirect(req.body.referrer);
else } else {
res.redirect(nconf.get('relative_path') + '/'); res.redirect(nconf.get('relative_path') + '/');
}
}); });
} else { } else {
res.redirect(nconf.get('relative_path') + '/register'); res.redirect(nconf.get('relative_path') + '/register');
@ -138,7 +143,7 @@
}); });
}); });
}); });
} };
Auth.login = function(username, password, next) { Auth.login = function(username, password, next) {
if (!username || !password) { if (!username || !password) {
@ -186,7 +191,7 @@
}); });
}); });
}); });
} };
passport.use(new passportLocal(Auth.login)); passport.use(new passportLocal(Auth.login));

@ -1,5 +1,8 @@
"use strict";
var nconf = require('nconf'), var nconf = require('nconf'),
controllers = require('./../controllers'), controllers = require('./../controllers'),
meta = require('./../meta'),
middleware = {}, middleware = {},
/*temp*/ /*temp*/
@ -152,7 +155,7 @@ module.exports = function(app, middleware) {
req: req, req: req,
res: res res: res
}, function (err, header) { }, 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.ready(function() {
plugins.fireHook('filter:server.create_routes', custom_routes, function(err, custom_routes) { plugins.fireHook('filter:server.create_routes', custom_routes, function(err, custom_routes) {
var routes = custom_routes.routes; var route,
for (var route in routes) { routes = custom_routes.routes;
for (route in routes) {
if (routes.hasOwnProperty(route)) { if (routes.hasOwnProperty(route)) {
(function(route) { (function(route) {
app[routes[route].method || 'get'](routes[route].route, function(req, res) { app[routes[route].method || 'get'](routes[route].route, function(req, res) {
@ -188,7 +193,7 @@ module.exports = function(app, middleware) {
req: options.req || req, req: options.req || req,
res: options.res || res res: options.res || res
}, function (err, header) { }, 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; var apiRoutes = custom_routes.api;
for (var route in apiRoutes) { for (route in apiRoutes) {
if (apiRoutes.hasOwnProperty(route)) { if (apiRoutes.hasOwnProperty(route)) {
(function(route) { (function(route) {
app[apiRoutes[route].method || 'get']('/api' + apiRoutes[route].route, function(req, res) { 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; var templateRoutes = custom_routes.templates;
for (var route in templateRoutes) { for (route in templateRoutes) {
if (templateRoutes.hasOwnProperty(route)) { if (templateRoutes.hasOwnProperty(route)) {
(function(route) { (function(route) {
app.get('/templates/' + templateRoutes[route].template, function(req, res) { app.get('/templates/' + templateRoutes[route].template, function(req, res) {
@ -223,4 +228,4 @@ module.exports = function(app, middleware) {
}); });
}); });
}); });
} };

@ -40,21 +40,7 @@ if(nconf.get('ssl')) {
(function (app) { (function (app) {
"use strict"; "use strict";
var clientScripts, var port = nconf.get('PORT') || nconf.get('port');
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;
});
});
});
logger.init(app); logger.init(app);
auth.registerApp(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\''); winston.info('Enabling \'trust proxy\'');
app.enable('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'); winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
} }

Loading…
Cancel
Save