updating nodebb executable so that it sends a NODE_ENV environment

variable in, and modified app.js and redis lib to read it.
v1.18.x
Julian Lam 12 years ago
parent f91e0848ee
commit 4d99870063

@ -4,6 +4,9 @@ var fs = require('fs'),
utils = require('./public/src/utils.js'), utils = require('./public/src/utils.js'),
args = {}; args = {};
// Runtime environment
global.env = process.env.NODE_ENV || 'production',
// Parse any passed-in arguments // Parse any passed-in arguments
process.argv.slice(2).forEach(function(value) { process.argv.slice(2).forEach(function(value) {
if (value.slice(0, 2) === '--') { if (value.slice(0, 2) === '--') {

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
clear clear
echo "Launching NodeBB" echo "Launching NodeBB in \"development\" mode"
supervisor --extensions 'node|js|tpl' -- app $1 NODE_ENV=development supervisor --extensions 'node|js|tpl' -- app $1

@ -1,8 +1,5 @@
(function(RedisDB) { (function(RedisDB) {
var PRODUCTION = false, var redis = require('redis'),
ERROR_LOGS = true,
redis = require('redis'),
utils = require('./../public/src/utils.js'); utils = require('./../public/src/utils.js');
RedisDB.exports = redis.createClient(global.config.redis.port, global.config.redis.host); RedisDB.exports = redis.createClient(global.config.redis.port, global.config.redis.host);
@ -13,14 +10,14 @@
RedisDB.exports.handle = function(error) { RedisDB.exports.handle = function(error) {
if (error !== null) { if (error !== null) {
if (PRODUCTION === false) { if (global.env !== 'production') {
console.log("################# ERROR LOG ####################"); console.log("################# ERROR LOG ####################");
console.log(error); console.log(error);
console.log(arguments.callee.name); console.log(arguments.callee.name);
console.log("################# ERROR LOG ####################"); console.log("################# ERROR LOG ####################");
throw new Error('RedisDB Error: ' + error); throw new Error(error);
} else if (ERROR_LOGS === true) { } else {
console.log('RedisDB Error: ' + error); console.log(error);
} }
} }
} }

@ -753,11 +753,15 @@ var utils = require('./../public/src/utils.js'),
}; };
User.go_online = function(uid) { 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) { User.go_offline = function(uid) {
RDB.srem('users:online', uid); RDB.srem('users:online', uid, function(err) {
if (err) RDB.handle(err);
});
}; };

@ -292,11 +292,7 @@ var express = require('express'),
app.get('/api/:method/:id*', api_method); app.get('/api/:method/:id*', api_method);
app.all('/test', function(req, res) { app.all('/test', function(req, res) {
var RDB = require('./redis.js'); res.send();
RDB.lpush('administrators', 1, function(err, data) {
// console.log(err, data);
res.send();
});
}); });

@ -55,11 +55,13 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
var hs = socket.handshake; var hs = socket.handshake;
var uid = users[hs.sessionID]; var uid = users[hs.sessionID];
userSockets[uid] = userSockets[uid] || []; // if (uid > 0) {
userSockets[uid].push(socket); userSockets[uid] = userSockets[uid] || [];
user.go_online(uid); userSockets[uid].push(socket);
user.go_online(uid);
socket.join('uid_' + uid);
socket.join('uid_' + uid);
// }
/*process.on('uncaughtException', function(err) { /*process.on('uncaughtException', function(err) {
// handle the error safely // 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.emit('event:connect', {status: 1});
socket.on('disconnect', function() { socket.on('disconnect', function() {
user.go_offline(uid); // if (uid > 0) {
delete users[hs.sessionID]; user.go_offline(uid);
var index = userSockets[uid].indexOf(socket); delete users[hs.sessionID];
if(index !== -1) { var index = userSockets[uid].indexOf(socket);
userSockets[uid].splice(index, 1); if(index !== -1) {
} userSockets[uid].splice(index, 1);
}
// }
}); });
socket.on('api:get_all_rooms', function(data) { socket.on('api:get_all_rooms', function(data) {

Loading…
Cancel
Save