Permalink
Browse files

Merge pull request #5 from shane-tomlinson/master

Only reverse the docs if there are docs.
  • Loading branch information...
2 parents e05af42 + d8afbe8 commit 265bca05860ea5432e902068ad9e31d98b43151d @jedp committed Oct 22, 2012
Showing with 15 additions and 8 deletions.
  1. +15 −8 lib/server.js
View
@@ -21,7 +21,7 @@ io.set('log level', 1);
*/
var db = module.exports.db = null;
-/*
+/*
* use the start() method to ensure the db is connected before
* starting the web server
*/
@@ -47,7 +47,7 @@ var start = module.exports.start = function() {
/*
* app configuration
- *
+ *
* manipulate this by setting in advance the env vars used by config.js
*/
@@ -79,22 +79,29 @@ app.get('/', function(req, res) {
*
* POST /wsapi/interaction_data
* required field:
- * data: stringified blob of json data conforming to
+ * data: stringified blob of json data conforming to
* https://wiki.mozilla.org/Privacy/Reviews/KPI_Backend#Example_data:
*
* GET /wsapi/interaction_data
* required params:
- * start: start timestamp
+ * start: start timestamp
* end: end timestamp
*/
io.sockets.on('connection', function(socket) {
db.fetchRange({limit:7, descending:true}, function(err, docs) {
- docs.reverse();
+ if (err) {
+ console.log(err);
+ return;
+ }
- docs.forEach(function(doc) {
- socket.volatile.emit('change', doc);
- });
+ if (docs) {
+ docs.reverse();
+
+ docs.forEach(function(doc) {
+ socket.volatile.emit('change', doc);
+ });
+ }
});
});

0 comments on commit 265bca0

Please sign in to comment.