Merge pull request #52 from bparees/db_toleration

attempt to init the db on every request
This commit is contained in:
Ben Parees 2016-06-29 14:17:48 -04:00 committed by GitHub
commit c56041b2c7
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 + '}');