Skip to content

Commit

Permalink
nconf and redis wrapper no longer global objects. jshinted app.js. up…
Browse files Browse the repository at this point in the history
…dated sockets.io to latest
  • Loading branch information
psychobunny committed Sep 17, 2013
1 parent eddddc6 commit 64b071f
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .jsbeautifyrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
183 changes: 92 additions & 91 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,114 +16,115 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// 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();
});
}
process.exit();
});
}
}());
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
3 changes: 2 additions & 1 deletion src/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var async = require('async'),
prompt = require('prompt'),
winston = require('winston'),
reds = require('reds'),
nconf = require('nconf');

install = {
questions: [{
Expand Down
3 changes: 2 additions & 1 deletion src/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
1 change: 1 addition & 0 deletions src/postTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion src/redis.js
Original file line number Diff line number Diff line change
@@ -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'));

Expand Down
3 changes: 2 additions & 1 deletion src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/threadTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
1 change: 1 addition & 0 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -517,5 +519,5 @@ var express = require('express'),

}(WebServer));

server.listen(nconf.get('PORT') || nconf.get('port'));

global.server = server;

0 comments on commit 64b071f

Please sign in to comment.