Merge pull request #52 from bparees/db_toleration
attempt to init the db on every request
This commit is contained in:
commit
c56041b2c7
1 changed files with 10 additions and 0 deletions
10
server.js
10
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 + '}');
|
||||
|
|
Loading…
Add table
Reference in a new issue