Skip to content

Commit

Permalink
Merge pull request #83 from guypod/master
Browse files Browse the repository at this point in the history
feat: added support for CloudFoundry
  • Loading branch information
guypod authored Jun 6, 2017
2 parents e24671d + 1fb49a5 commit f4f3ed2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
var cfenv = require("cfenv");
var Schema = mongoose.Schema;

var Todo = new Schema({
Expand All @@ -15,10 +16,21 @@ var User = new Schema({

mongoose.model('User', User);

// CloudFoundry env vars
var mongoCFUri = cfenv.getAppEnv().getServiceURL('goof-mongo');
console.log(JSON.stringify(cfenv.getAppEnv()));

// Default Mongo URI is local
var mongoUri = 'mongodb://localhost/express-todo';
if (process.env.MONGOLAB_URI) {

// CloudFoundry Mongo URI
if (mongoCFUri) {
mongoUri = mongoCFUri;
} else if (process.env.MONGOLAB_URI) {
// Generic (plus Heroku) env var support
mongoUri = process.env.MONGOLAB_URI;
}
console.log("Using Mongo URI " + mongoUri);

mongoose.connect(mongoUri);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"body-parser": "1.9.0",
"cfenv": "^1.0.4",
"cookie-parser": "1.3.3",
"ejs": "1.0.0",
"ejs-locals": "1.0.2",
Expand Down

0 comments on commit f4f3ed2

Please sign in to comment.