Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: added support for CloudFoundry
  • Loading branch information
guypod committed Jun 6, 2017
commit 1fb49a57590352bf743cb810f23eb6b537285f7c
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