From 3b643fc6bc946e1bd54510a2af8f1b530f0daa90 Mon Sep 17 00:00:00 2001 From: Ben Parees Date: Wed, 29 Jun 2016 13:59:22 -0400 Subject: [PATCH] attempt to init the db on every request --- server.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 + '}');