attempt to init the db on every request
This commit is contained in:
parent
46537887f2
commit
3b643fc6bc
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) {
|
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) {
|
if (db) {
|
||||||
var col = db.collection('counts');
|
var col = db.collection('counts');
|
||||||
// Create a document with request IP and current time of request
|
// 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) {
|
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) {
|
if (db) {
|
||||||
db.collection('counts').count(function(err, count ){
|
db.collection('counts').count(function(err, count ){
|
||||||
res.send('{ pageCount: ' + count + '}');
|
res.send('{ pageCount: ' + count + '}');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue