attempt to init the db on every request

This commit is contained in:
Ben Parees 2016-06-29 13:59:22 -04:00
parent 46537887f2
commit 3b643fc6bc
1 changed files with 10 additions and 0 deletions

View File

@ -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 + '}');