How to call Cloud Foundry API from a node.js application deployed?


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Hi,

I would like to know how to call cloud foundry API from a node.js application.

From local, it is very easy to call the API using a absolute address:

https://api.MY_PUBLIC_IP.xip.io/v2/info
http://apidocs.cloudfoundry.org/214/info/get_info.html

but when I deploy the node application to the platform, I can't connect with the API and I receive the following error:

{"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}}

I checked Application Security Group, but no rule is associated to the space used with the application.
http://docs.pivotal.io/pivotalcf/adminguide/app-sec-groups.html

Does exist a way to call the API from a application deployed?
Does exist a VCAP variable similar to: process.env.VCAP_APP_PORT to avoid this problem?

Many thanks in advance

Juan Antonio


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

I have tested with this combinations:

var API_URL = "http://api." + process.env.VCAP_APP_HOST + ".xip.io/v2/info";
var API_URL = "http://api." + process.env.VCAP_APP_HOST + "/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + "/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + ".xip.io/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_ADDR + ".xip.io/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + ".xip.io/v2/info";
var API_URL = "//api." + process.env.VCAP_APP_HOST + "/v2/info";

but I failed with the idea to get this data:
http://apidocs.cloudfoundry.org/214/info/get_info.html

How to connect?


Amit Kumar Gupta
 

Have you tried the same thing that worked before:
https://api.MY_PUBLIC_IP.xip.io/v2/info?

That public IP is your load balancer, HA Proxy, or router; traffic there
will know how to get routed to the CC's advertising the "
api.MY_PUBLIC_IP.xip.io" route.

The things like CF_INSTANCE_IP are the IP of the container (running your
node app), so it will definitely not work.

Best,
Amit

On Tue, Aug 11, 2015 at 12:05 PM, Juan Antonio Breña Moral <
bren(a)juanantonio.info> wrote:

I have tested with this combinations:

var API_URL = "http://api." + process.env.VCAP_APP_HOST + ".xip.io/v2/info
";
var API_URL = "http://api." + process.env.VCAP_APP_HOST + "/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + "/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + ".
xip.io/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_ADDR + ".
xip.io/v2/info";
var API_URL = "http://api." + process.env.CF_INSTANCE_IP + ".
xip.io/v2/info";
var API_URL = "//api." + process.env.VCAP_APP_HOST + "/v2/info";

but I failed with the idea to get this data:
http://apidocs.cloudfoundry.org/214/info/get_info.html

How to connect?


Juan Antonio Breña Moral <bren at juanantonio.info...>
 

Good morning,

Yes I tried but the connection failed:

{"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}}

Later, I tryed with curl in the same host where I installed CF and I had success:

curl "https://api.MY_PUBLIC_IP.xip.io/v2/info" -X GET -k

{"name":"vcap","build":"2222","support":"http://support.cloudfoundry.com","version":2,"description":"Cloud Foundry sponsored by Pivotal","authorization_endpoint":"https://uaa.MY_PUBLIC_IP.xip.io","token_endpoint":"https://uaa.MY_PUBLIC_IP.xip.io","min_cli_version":null,"min_recommended_cli_version":null,"api_version":"2.25.0","logging_endpoint":"wss://loggregator.MY_PUBLIC_IP.xip.io:4443"}

Why from CURL, I can't connect and from the application is not possible?
I have to open some port in CF?

Juan Antonio


Amit Kumar Gupta
 

You may need to configure the application-level security groups to allow
apps running in containers to talk to system components such as the Cloud
Controllers. You will likely only want to allow this for trusted
applications, and thus may wish to bind these more permissive security
group settings to the particular space in which your Node app resides. You
can read more about security groups here:

http://docs.pivotal.io/pivotalcf/adminguide/app-sec-groups.html

On Wed, Aug 12, 2015 at 2:22 AM, Juan Antonio Breña Moral <
bren(a)juanantonio.info> wrote:

Good morning,

Yes I tried but the connection failed:


{"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}}

Later, I tryed with curl in the same host where I installed CF and I had
success:

curl "https://api.MY_PUBLIC_IP.xip.io/v2/info" -X GET -k

{"name":"vcap","build":"2222","support":"http://support.cloudfoundry.com","version":2,"description":"Cloud
Foundry sponsored by Pivotal","authorization_endpoint":"
https://uaa.MY_PUBLIC_IP.xip.io","token_endpoint":"
https://uaa.MY_PUBLIC_IP.xip.io
","min_cli_version":null,"min_recommended_cli_version":null,"api_version":"2.25.0","logging_endpoint":"wss://
loggregator.MY_PUBLIC_IP.xip.io:4443"}

Why from CURL, I can't connect and from the application is not possible?
I have to open some port in CF?

Juan Antonio