diff --git a/app.js b/app.js index d3b73178e4..57a04f3810 100644 --- a/app.js +++ b/app.js @@ -4,6 +4,9 @@ var fs = require('fs'), utils = require('./public/src/utils.js'), args = {}; +// Runtime environment +global.env = process.env.NODE_ENV || 'production', + // Parse any passed-in arguments process.argv.slice(2).forEach(function(value) { if (value.slice(0, 2) === '--') { diff --git a/nodebb b/nodebb index ab0192539f..b318989623 100755 --- a/nodebb +++ b/nodebb @@ -1,4 +1,4 @@ #!/bin/bash clear -echo "Launching NodeBB" -supervisor --extensions 'node|js|tpl' -- app $1 \ No newline at end of file +echo "Launching NodeBB in \"development\" mode" +NODE_ENV=development supervisor --extensions 'node|js|tpl' -- app $1 \ No newline at end of file diff --git a/src/redis.js b/src/redis.js index 79a13da47d..8ef71f16bd 100644 --- a/src/redis.js +++ b/src/redis.js @@ -1,8 +1,5 @@ (function(RedisDB) { - var PRODUCTION = false, - ERROR_LOGS = true, - - redis = require('redis'), + var redis = require('redis'), utils = require('./../public/src/utils.js'); RedisDB.exports = redis.createClient(global.config.redis.port, global.config.redis.host); @@ -13,14 +10,14 @@ RedisDB.exports.handle = function(error) { if (error !== null) { - if (PRODUCTION === false) { + if (global.env !== 'production') { console.log("################# ERROR LOG ####################"); console.log(error); console.log(arguments.callee.name); console.log("################# ERROR LOG ####################"); - throw new Error('RedisDB Error: ' + error); - } else if (ERROR_LOGS === true) { - console.log('RedisDB Error: ' + error); + throw new Error(error); + } else { + console.log(error); } } } diff --git a/src/user.js b/src/user.js index 887263cba9..90f438fe66 100644 --- a/src/user.js +++ b/src/user.js @@ -753,11 +753,15 @@ var utils = require('./../public/src/utils.js'), }; User.go_online = function(uid) { - RDB.sadd('users:online', uid); + RDB.sadd('users:online', uid, function(err) { + if (err) RDB.handle(err); + }); }; User.go_offline = function(uid) { - RDB.srem('users:online', uid); + RDB.srem('users:online', uid, function(err) { + if (err) RDB.handle(err); + }); }; diff --git a/src/webserver.js b/src/webserver.js index 5ec8b0a946..aa56536f5d 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -292,11 +292,7 @@ var express = require('express'), app.get('/api/:method/:id*', api_method); app.all('/test', function(req, res) { - var RDB = require('./redis.js'); - RDB.lpush('administrators', 1, function(err, data) { - // console.log(err, data); - res.send(); - }); + res.send(); }); diff --git a/src/websockets.js b/src/websockets.js index 1579f8b50f..97b55547e6 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -55,11 +55,13 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), var hs = socket.handshake; var uid = users[hs.sessionID]; - userSockets[uid] = userSockets[uid] || []; - userSockets[uid].push(socket); - user.go_online(uid); - - socket.join('uid_' + uid); + // if (uid > 0) { + userSockets[uid] = userSockets[uid] || []; + userSockets[uid].push(socket); + user.go_online(uid); + + socket.join('uid_' + uid); + // } /*process.on('uncaughtException', function(err) { // handle the error safely @@ -70,12 +72,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), socket.emit('event:connect', {status: 1}); socket.on('disconnect', function() { - user.go_offline(uid); - delete users[hs.sessionID]; - var index = userSockets[uid].indexOf(socket); - if(index !== -1) { - userSockets[uid].splice(index, 1); - } + // if (uid > 0) { + user.go_offline(uid); + delete users[hs.sessionID]; + var index = userSockets[uid].indexOf(socket); + if(index !== -1) { + userSockets[uid].splice(index, 1); + } + // } }); socket.on('api:get_all_rooms', function(data) {