1. Alvaro Videla
  2. cloudstagram

Commits

Alvaro Videla  committed 6270fe9

updates service logic for cf v2

  • Participants
  • Parent commits e2fe4bf
  • Branches master

Comments (0)

Files changed (2)

File lib/cloudFoundryUtil.js

View file
-var cloudfoundry = require('cloudfoundry');
+var vcap_services = JSON.parse(process.env.VCAP_SERVICES);
+var vcap_application = JSON.parse(process.env.VCAP_APPLICATION);
 
 function getRabbitUrl(rabbitServiceName) {
-    return "amqp://localhost";
+    return vcap_services['cloudamqp-n/a'][0]['credentials']['uri'];
 }
 
 function getRedisCredentials(redisServiceName) {
-    var credentials = {};
-    if (cloudfoundry.cloud && cloudfoundry.redis) {
-	var service;
-	if(redisServiceName) {
-	    service = cloudfoundry.redis[redisServiceName];
-	} else {//select first one
-	    for( var name in cloudfoundry.redis) {
-		service = cloudfoundry.redis[name];
-		break;
-	    };			
-	}
-	if(service) {
-	    credentials = service.credentials;
-	}
-    }
-    return credentials;
-}
-
-function getMongoCredentials(dbServiceName) {
-    return {
-        "hostname": "localhost",
-        "port": 27017,
-        "name": "",
-        "db": "cloudstagram"
-    };
+    console.log(vcap_services['rediscloud-n/a'][0]['credentials']);
+    return vcap_services['rediscloud-n/a'][0]['credentials'];
 }
 
 function getMongoUrl(dbServiceName) {
-    var credentials = getMongoCredentials();
-    var mongoUrl = "mongodb://" + credentials.hostname
-        + ":" + credentials.port + "/" + credentials.db;
-
-    console.log("MongoUrl: " + mongoUrl);
-    return mongoUrl;
+    return vcap_services['mongolab-n/a'][0]['credentials']['uri'];
 }
 
 function getInstanceId() {
-    if (cloudfoundry.cloud) {
-        return cloudfoundry.app.instance_id;
-    } else {
-        return "pid-" + process.pid;
-    }
+    return vcap_application['instance_id'];
 }
 
 exports.getRabbitUrl = getRabbitUrl;
-exports.getRedisCredentials = getRedisCredentials;
-exports.getMongoCredentials = getMongoCredentials;
 exports.getMongoUrl = getMongoUrl;
+exports.getRedisCredentials = getRedisCredentials;
 exports.getInstanceId = getInstanceId;

File lib/services.js

View file
 }
 
 function getRedisClient() {
-    return redis.createClient();
+    var creds = cf_utils.getRedisCredentials();
+    var client = redis.createClient(creds['port'], creds['hostname']);
+    client.auth(creds['password'], function() {
+        console.log("Redis Connected!");
+    });
+    return client;
 }
 
 var rabbitmqConn;