Skip to content

Node.js based forum software built for the modern web

log server errors in browser added uid to posts

Baris Soner Usakli20aa5d439eb3
diff --git a/.project b/.project
new file mode 100644
index 0000000000..d382cb0b53
--- /dev/null
+++ b/.project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>node-forum</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.projects.webnature</nature>
+ </natures>
+</projectDescription>
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);
});