Skip to content

Commit

Permalink
update connexion
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddjian committed May 18, 2018
1 parent 560a5f1 commit 5464799
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 29 additions & 1 deletion lib/short.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,38 @@ ID.configure({
*/

exports.connect = function(mongodb) {

const options = {
autoIndex: true, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 40, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
//bufferMaxEntries: 0
};


if (mongoose.connection.readyState === 0)
mongoose.connect(mongodb);

exports.connection = mongoose.connection;
setTimeout(function() {
let mongoDB = mongoose.connect(mongoFullUrl, options)
.then(function(){
log('Successfully connected to database ' + mongoFullUrl);
})
.catch(function(err) {
// Check error in initial connection. There is no 2nd param to the callback.
log('Error when connecting to db ' + mongoFullUrl + '\n\r' + err);
});

mongoose.set('debug', app.get('debug'));

//return mongoDB;

exports.connection = mongoDB;
}, 60);

//exports.connection = mongoose.connection;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ddtraceweb_short",
"version": "2.7.0",
"version": "2.7.2",
"author": "Edward Hotchkiss <edward@edwardhotchkiss.com>",
"description": "Node.js URL Shortener backed by Mongoose.js",
"contributors": [
Expand Down Expand Up @@ -68,7 +68,7 @@
"node": ">=0.10.0"
},
"dependencies": {
"mongoose": "^4.11.14",
"mongoose": "^5.0.16",
"node-promise": "0.5.8",
"short-id": "0.1.0-1"
},
Expand Down

0 comments on commit 5464799

Please sign in to comment.