swampfox07
swampfox07

Reputation: 51

How to use VCAP_APP_PORT

how do you get cloudfoundry to assign a port? I am adding applications and I'd like to have a different port for each but VCAP_APP_PORT is not set. VCAP_APP_HOST is set but VCAP_APP_PORT is not.

Upvotes: 2

Views: 3321

Answers (2)

anon
anon

Reputation:

Cloud Foundry will automatically assign each application instance an IP address and port and these values are accessible in the VCAP_* variable as Dan describes. You don't get to tell Cloud Foundry which port you prefer. Each instance of your app may receive a different IP address and port, so you should always interrogate the environment to find out what they are if you need that information.

Upvotes: 2

Dan Higham
Dan Higham

Reputation: 3984

Take a look at http://show-env.cloudfoundry.com/

It's a node application I knocked together just to output the environment and the request headers when you call it, the code looks like this;

var http = require('http');
var util = require('util');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write(util.inspect(process.env));
  res.write("\n\n************\n\n");
  res.end(util.inspect(req.headers));

}).listen(3000);

You can see the VCAP_APP_PORT in the output;

Environment output It would be handy to know which framework you are using, however, all these variables should be stored in the system environment so it shouldn't really matter.

Upvotes: 2

Related Questions