From 20aa5d439eb38493ea6c3d68f70a38bb73a76659 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 30 Apr 2013 12:40:16 -0400 Subject: [PATCH] log server errors in browser added uid to posts --- .project | 12 ++++++++++++ app.js | 8 +++++++- public/src/app.js | 4 ++++ src/posts.js | 10 ++++++---- src/topics.js | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 0000000000..d382cb0b53 --- /dev/null +++ b/.project @@ -0,0 +1,12 @@ + + + node-forum + + + + + + + com.aptana.projects.webnature + + diff --git a/app.js b/app.js index 8732c4aee4..b9759de5bc 100644 --- a/app.js +++ b/app.js @@ -17,6 +17,12 @@ global.modules = modules; // global.uid = 1; +process.on('uncaughtException', function(err) { + // handle the error safely + console.log("error message "+err); + global.socket.emit('event:consolelog',{type:'uncaughtException',stack:err.stack,error:err.toString()}); +}); + (function(config) { config['ROOT_DIRECTORY'] = __dirname; @@ -25,6 +31,6 @@ global.modules = modules; // modules.webserver.init(); modules.websockets.init(); - + }(global.configuration)); \ No newline at end of file diff --git a/public/src/app.js b/public/src/app.js index 0fdd83a550..8b50d34af6 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -18,6 +18,10 @@ var socket, socket.on('event:alert', function(data) { app.alert(data); }); + + socket.on('event:consolelog', function(data) { + console.log(data); + }); }, async: false diff --git a/src/posts.js b/src/posts.js index 78e55d4562..c34d088232 100644 --- a/src/posts.js +++ b/src/posts.js @@ -62,13 +62,15 @@ var RDB = require('./redis.js'); }; - Posts.create = function(content, callback) { - if (global.uid === null) return; - + Posts.create = function(uid, content, callback) { + console.log("global uid "+uid); + + if (uid === null) return; + RDB.incr('global:next_post_id', function(pid) { // Posts Info RDB.set('pid:' + pid + ':content', content); - RDB.set('pid:' + pid + ':uid', global.uid); + RDB.set('pid:' + pid + ':uid', uid); RDB.set('pid:' + pid + ':timestamp', new Date().getTime()); // User Details - move this out later diff --git a/src/topics.js b/src/topics.js index cd06162091..fdc76cd8c7 100644 --- a/src/topics.js +++ b/src/topics.js @@ -137,7 +137,7 @@ var RDB = require('./redis.js'), RDB.set('topic:slug:' + slug + ':tid', tid); // Posts - posts.create(content, function(pid) { + posts.create(uid, content, function(pid) { RDB.lpush('tid:' + tid + ':posts', pid); });