Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

added cloudfoundry support #29

Closed
wants to merge 1 commit into from

3 participants

@vishesh04

now user will be able to install iodocs on cloudfoundry without any changes to code.app was using process.env.REDISTOGO_URL to detect Heroku , I have used process.env.VCAP_SERVICES to detect cloudfoundry also.

@phairow
Owner

The provider specific settings do not belong in the core application code. We will need to decide a better way to do this. In the mean time this provider specific fork should be maintained separately until this can be made pluggable in the core application.

@phairow phairow closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 17, 2012
  1. @vishesh04

    added cloudfoundry support

    vishesh04 authored
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 11 deletions.
  1. +29 −11 app.js
View
40 app.js
@@ -50,15 +50,27 @@ try {
var defaultDB = '0';
var db;
-if (process.env.REDISTOGO_URL) {
+/*default settings , will be overridden based on platform in case of cloudfoundry or Heroku. */
+var redisHost=config.redis.host;
+var redisPort=config.redis.port;
+var redisPassword=config.redis.password;
+
+if (process.env.VCAP_SERVICES) { //if using cloudfoundry
+ var vcapServices = JSON.parse(process.env.VCAP_SERVICES);
+ var cfRedis = vcapServices['redis-2.2'][0]; //'redis-2.2' should be replaced by redis service name,if different
+ redisHost = cfRedis.credentials.hostname;
+ redisPort = cfRedis.credentials.port;
+ redisPassword = cfRedis.credentials.password;
+} else if(process.env.REDISTOGO_URL) { //if using Heroku
var rtg = require("url").parse(process.env.REDISTOGO_URL);
- db = require("redis").createClient(rtg.port, rtg.hostname);
- db.auth(rtg.auth.split(":")[1]);
-} else {
- db = redis.createClient(config.redis.port, config.redis.host);
- db.auth(config.redis.password);
+ redisHost=rtg.hostname;
+ redisPort=rtg.port;
+ redisPassword=rtg.auth.split(":")[1];
}
+db = require("redis").createClient(redisPort, redisHost);
+db.auth(redisPassword);
+
db.on("error", function(err) {
if (config.debug) {
console.log("Error " + err);
@@ -79,11 +91,17 @@ fs.readFile('public/data/apiconfig.json', 'utf-8', function(err, data) {
var app = module.exports = express.createServer();
-if (process.env.REDISTOGO_URL) {
+if (process.env.VCAP_SERVICES) { //if using cloudfoundry
+ var vcapServices = JSON.parse(process.env.VCAP_SERVICES);
+ var cfRedis = vcapServices['redis-2.2'][0]; //'redis-2.2' should be replaced by redis service name,if different
+ config.redis.host = cfRedis.credentials.hostname;
+ config.redis.port = cfRedis.credentials.port;
+ config.redis.password = cfRedis.credentials.password;
+}else if (process.env.REDISTOGO_URL) { //if using Heroku
var rtg = require("url").parse(process.env.REDISTOGO_URL);
- config.redis.host = rtg.hostname;
- config.redis.port = rtg.port;
- config.redis.password = rtg.auth.split(":")[1];
+ config.redis.host = rtg.hostname;
+ config.redis.port = rtg.port;
+ config.redis.password = rtg.auth.split(":")[1];
}
app.configure(function() {
@@ -661,7 +679,7 @@ app.get('/:api([^\.]+)', function(req, res) {
// Only listen on $ node app.js
if (!module.parent) {
- var port = process.env.PORT || config.port;
+ var port = process.env.VCAP_APP_PORT || process.env.PORT || config.port; //cloudfoundry || Heroku || config file settings
app.listen(port);
console.log("Express server listening on port %d", app.address().port);
}
Something went wrong with that request. Please try again.