From 64b071f277324d8c29c14343e38cbcdca99c7e13 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 17 Sep 2013 15:38:50 -0400 Subject: [PATCH 1/4] nconf and redis wrapper no longer global objects. jshinted app.js. updated sockets.io to latest --- .jsbeautifyrc | 2 +- app.js | 183 ++++++++++++++++++++++---------------------- package.json | 2 +- src/categories.js | 3 +- src/feed.js | 3 +- src/install.js | 1 + src/meta.js | 3 +- src/postTools.js | 1 + src/redis.js | 3 +- src/routes/admin.js | 3 +- src/routes/api.js | 3 +- src/routes/user.js | 9 ++- src/sitemap.js | 1 + src/threadTools.js | 3 +- src/user.js | 1 + src/webserver.js | 6 +- 16 files changed, 121 insertions(+), 106 deletions(-) diff --git a/.jsbeautifyrc b/.jsbeautifyrc index 2245d6adb6..5102dfec5f 100644 --- a/.jsbeautifyrc +++ b/.jsbeautifyrc @@ -5,7 +5,7 @@ "indent_with_tabs": false, "preserve_newlines": true, "max_preserve_newlines": 10, - "jslint_happy": false, + "jslint_happy": true, "brace_style": "collapse", "keep_array_indentation": false, "keep_function_indentation": false, diff --git a/app.js b/app.js index 546ea1c8a2..b0f0a02e9c 100644 --- a/app.js +++ b/app.js @@ -16,114 +16,115 @@ along with this program. If not, see . */ -// Configuration setup -nconf = require('nconf'); -nconf.argv().env(); +(function() { + "use strict"; -var fs = require('fs'), - winston = require('winston'), - pkg = require('./package.json'), - url = require('url'); + // Configuration setup + var nconf = require('nconf'); + nconf.argv().env(); -// Runtime environment -global.env = process.env.NODE_ENV || 'production'; + var fs = require('fs'), + winston = require('winston'), + pkg = require('./package.json'); + // Runtime environment + global.env = process.env.NODE_ENV || 'production'; + winston.remove(winston.transports.Console); + winston.add(winston.transports.Console, { + colorize: true + }); -winston.remove(winston.transports.Console); -winston.add(winston.transports.Console, { - colorize: true -}); - -winston.add(winston.transports.File, { - filename: 'error.log', - level: 'error' -}); - -// TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed -winston.err = function(err) { - winston.error(err.stack); -}; + winston.add(winston.transports.File, { + filename: 'error.log', + level: 'error' + }); -// Log GNU copyright info along with server info -winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013 DesignCreatePlay Inc.'); -winston.info('This program comes with ABSOLUTELY NO WARRANTY.'); -winston.info('This is free software, and you are welcome to redistribute it under certain conditions.'); -winston.info(''); + // TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed + winston.err = function(err) { + winston.error(err.stack); + }; -if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) { - // Load server-side config - nconf.file({ - file: __dirname + '/config.json' - }); + // Log GNU copyright info along with server info + winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013 DesignCreatePlay Inc.'); + winston.info('This program comes with ABSOLUTELY NO WARRANTY.'); + winston.info('This is free software, and you are welcome to redistribute it under certain conditions.'); + winston.info(''); var meta = require('./src/meta.js'); - nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); - nconf.set('upload_url', nconf.get('url') + 'uploads/'); + if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) { + // Load server-side config + nconf.file({ + file: __dirname + '/config.json' + }); + + nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); + nconf.set('upload_url', nconf.get('url') + 'uploads/'); - winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.'); - if (process.env.NODE_ENV === 'development') winston.info('Base Configuration OK.'); + winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.'); - meta.configs.init(function() { - // Initial setup for Redis & Reds - var reds = require('reds'); - RDB = require('./src/redis.js'); - reds.createClient = function() { - return reds.client || (reds.client = RDB); + if (process.env.NODE_ENV === 'development') { + winston.info('Base Configuration OK.'); } - var categories = require('./src/categories.js'), - templates = require('./public/src/templates.js'), - webserver = require('./src/webserver.js'), - websockets = require('./src/websockets.js'), - plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself - admin = { - 'categories': require('./src/admin/categories.js') - }; + meta.configs.init(function() { + // Initial setup for Redis & Reds + var reds = require('reds'), + RDB = require('./src/redis.js'); - global.templates = {}; - templates.init([ - 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', - 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', - 'emails/header', 'emails/footer', + reds.createClient = function() { + return reds.client || (reds.client = RDB); + }; - 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' - ]); + var templates = require('./public/src/templates.js'), + webserver = require('./src/webserver.js'), + websockets = require('./src/websockets.js'), + plugins = require('./src/plugins'); // Don't remove this - plugins initializes itself + + global.templates = {}; + templates.init([ + 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', + 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', + 'emails/header', 'emails/footer', + + 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' + ]); + + templates.ready(webserver.init); + }); + + } else if (nconf.get('upgrade')) { + nconf.file({ + file: __dirname + '/config.json' + }); + + meta.configs.init(function() { + require('./src/upgrade').upgrade(); + }); + } else { + // New install, ask setup questions + if (nconf.get('setup')) { + winston.info('NodeBB Setup Triggered via Command Line'); + } + else { + winston.warn('Configuration not found, starting NodeBB setup'); + } - templates.ready(webserver.init); - }); + var install = require('./src/install'); -} else if (nconf.get('upgrade')) { - nconf.file({ - file: __dirname + '/config.json' - }); - var meta = require('./src/meta.js'); + winston.info('Welcome to NodeBB!'); + winston.info('This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.'); + winston.info('Press enter to accept the default setting (shown in brackets).'); - meta.configs.init(function() { - require('./src/upgrade').upgrade(); - }); -} else { - // New install, ask setup questions - if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line'); - else winston.warn('Configuration not found, starting NodeBB setup'); - - var install = require('./src/install'), - meta = { - config: {} - }; - - winston.info('Welcome to NodeBB!'); - winston.info('This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.'); - winston.info('Press enter to accept the default setting (shown in brackets).'); - - install.setup(function(err) { - if (err) { - winston.error('There was a problem completing NodeBB setup: ', err.message); - } else { - winston.info('NodeBB Setup Completed.'); - } + install.setup(function(err) { + if (err) { + winston.error('There was a problem completing NodeBB setup: ', err.message); + } else { + winston.info('NodeBB Setup Completed.'); + } - process.exit(); - }); -} \ No newline at end of file + process.exit(); + }); + } +}()); \ No newline at end of file diff --git a/package.json b/package.json index af8c787d61..d34cef3a13 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "app.js", "dependencies": { - "socket.io": "~0.9.14", + "socket.io": "~0.9.16", "redis": "0.8.3", "express": "3.2.0", "express-namespace": "0.1.1", diff --git a/src/categories.js b/src/categories.js index 985f2a3df8..2ad1b6226b 100644 --- a/src/categories.js +++ b/src/categories.js @@ -4,7 +4,8 @@ var RDB = require('./redis.js'), user = require('./user.js'), async = require('async'), topics = require('./topics.js'), - winston = require('winston'); + winston = require('winston'), + nconf = require('nconf'); (function(Categories) { diff --git a/src/feed.js b/src/feed.js index fed447b7b7..f7a57ecf94 100644 --- a/src/feed.js +++ b/src/feed.js @@ -6,7 +6,8 @@ fs = require('fs'), rss = require('rss'), winston = require('winston'), - path = require('path'); + path = require('path'), + nconf = require('nconf'); Feed.defaults = { ttl: 60, diff --git a/src/install.js b/src/install.js index 3665b89263..d947ac4a5d 100644 --- a/src/install.js +++ b/src/install.js @@ -6,6 +6,7 @@ var async = require('async'), prompt = require('prompt'), winston = require('winston'), reds = require('reds'), + nconf = require('nconf'); install = { questions: [{ diff --git a/src/meta.js b/src/meta.js index 73a938a914..5326c46315 100644 --- a/src/meta.js +++ b/src/meta.js @@ -3,7 +3,8 @@ var utils = require('./../public/src/utils.js'), async = require('async'), path = require('path'), fs = require('fs'), - winston = require('winston'); + winston = require('winston'), + nconf = require('nconf'); (function(Meta) { diff --git a/src/postTools.js b/src/postTools.js index c88ca4405b..5917d8c83b 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -4,6 +4,7 @@ var RDB = require('./redis.js'), threadTools = require('./threadTools.js'), user = require('./user.js'), async = require('async'), + nconf = require('nconf'), utils = require('../public/src/utils'), plugins = require('./plugins'), diff --git a/src/redis.js b/src/redis.js index d8e1c750ba..5413f58651 100644 --- a/src/redis.js +++ b/src/redis.js @@ -1,7 +1,8 @@ (function(RedisDB) { var redis = require('redis'), utils = require('./../public/src/utils.js'), - winston = require('winston'); + winston = require('winston'), + nconf = require('nconf'); RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); diff --git a/src/routes/admin.js b/src/routes/admin.js index f74aad3b2d..4a8f1a13b4 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -5,7 +5,8 @@ var user = require('./../user.js'), pkg = require('./../../package.json'), categories = require('./../categories.js'), plugins = require('../plugins'), - winston = require('winston'); + winston = require('winston'), + nconf = require('nconf'); (function(Admin) { Admin.isAdmin = function(req, res, next) { diff --git a/src/routes/api.js b/src/routes/api.js index 437650829e..bc41467e4e 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -5,7 +5,8 @@ var user = require('./../user.js'), utils = require('./../../public/src/utils.js'), pkg = require('../../package.json'), meta = require('./../meta.js'), - path = require('path'); + path = require('path'), + nconf = require('nconf'); (function(Api) { diff --git a/src/routes/user.js b/src/routes/user.js index 3bfabf59f0..0667751da1 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -4,7 +4,8 @@ var user = require('./../user.js'), fs = require('fs'), utils = require('./../../public/src/utils.js'), path = require('path'), - winston = require('winston'); + winston = require('winston'), + nconf = require('nconf'); (function(User) { User.create_routes = function(app) { @@ -157,7 +158,7 @@ var user = require('./../user.js'), return; } - var absolutePath = path.join(process.cwd(), global.nconf.get('upload_path'), path.basename(oldpicture)); + var absolutePath = path.join(process.cwd(), nconf.get('upload_path'), path.basename(oldpicture)); fs.unlink(absolutePath, function(err) { if (err) { @@ -178,7 +179,7 @@ var user = require('./../user.js'), } var filename = uid + '-profileimg' + extension; - var uploadPath = path.join(process.cwd(), global.nconf.get('upload_path'), filename); + var uploadPath = path.join(process.cwd(), nconf.get('upload_path'), filename); winston.info('Attempting upload to: ' + uploadPath); @@ -188,7 +189,7 @@ var user = require('./../user.js'), is.on('end', function() { fs.unlinkSync(tempPath); - var imageUrl = global.nconf.get('upload_url') + filename; + var imageUrl = nconf.get('upload_url') + filename; user.setUserField(uid, 'uploadedpicture', imageUrl); user.setUserField(uid, 'picture', imageUrl); diff --git a/src/sitemap.js b/src/sitemap.js index 7e68fa8ec7..26be952b21 100644 --- a/src/sitemap.js +++ b/src/sitemap.js @@ -2,6 +2,7 @@ var path = require('path'), async = require('async'), sm = require('sitemap'), url = require('url'), + nconf = require('nconf'), categories = require('./categories'), topics = require('./topics'), sitemap = { diff --git a/src/threadTools.js b/src/threadTools.js index 5e189fee3b..d4c9ab682b 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -8,7 +8,8 @@ var RDB = require('./redis.js'), reds = require('reds'), topicSearch = reds.createSearch('nodebbtopicsearch'), winston = require('winston'), - meta = require('./meta'); + meta = require('./meta'), + nconf = require('nconf'); (function(ThreadTools) { diff --git a/src/user.js b/src/user.js index 60ed7ce4bb..c3e700cd20 100644 --- a/src/user.js +++ b/src/user.js @@ -9,6 +9,7 @@ var utils = require('./../public/src/utils.js'), notifications = require('./notifications.js'), topics = require('./topics.js'), async = require('async'), + nconf = require('nconf'), userSearch = require('reds').createSearch('nodebbusersearch'); (function(User) { diff --git a/src/webserver.js b/src/webserver.js index 7dff3c792b..07c97bf3d8 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -21,7 +21,8 @@ var express = require('express'), auth = require('./routes/authentication.js'), meta = require('./meta.js'), feed = require('./feed'), - plugins = require('./plugins'); + plugins = require('./plugins'), + nconf = require('nconf'); (function(app) { var templates = null; @@ -116,6 +117,7 @@ var express = require('express'), module.exports.init = function() { templates = global.templates; + server.listen(nconf.get('PORT') || nconf.get('port')); } auth.initialize(app); @@ -517,5 +519,5 @@ var express = require('express'), }(WebServer)); -server.listen(nconf.get('PORT') || nconf.get('port')); + global.server = server; \ No newline at end of file From a01a7ae5fc0ee18f7023ff32605b738193587939 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 17 Sep 2013 15:46:22 -0400 Subject: [PATCH 2/4] fixed following.tpl and followers.tpl layout (broken from BS3 merge) --- public/templates/followers.tpl | 2 +- public/templates/following.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/templates/followers.tpl b/public/templates/followers.tpl index f2fa798853..205355aef8 100644 --- a/public/templates/followers.tpl +++ b/public/templates/followers.tpl @@ -1,5 +1,5 @@ -
+