diff --git a/server.js b/server.js index 38fd2ee..531d790 100644 --- a/server.js +++ b/server.js @@ -57,6 +57,11 @@ var initDb = function(callback) { }; app.get('/', function (req, res) { + // try to initialize the db on every request if it's not already + // initialized. + if (!db) { + initDb(function(err){}); + } if (db) { var col = db.collection('counts'); // Create a document with request IP and current time of request @@ -70,6 +75,11 @@ app.get('/', function (req, res) { }); app.get('/pagecount', function (req, res) { + // try to initialize the db on every request if it's not already + // initialized. + if (!db) { + initDb(function(err){}); + } if (db) { db.collection('counts').count(function(err, count ){ res.send('{ pageCount: ' + count + '}');