Using http proxy in node.js apigee app

Not applicable

I'm writing a node.js application in apigee. This node.js application requires sending http requests to internet i.e. out of local network. I'm using npm's request module to make http requests.

To reach outside local network, I need to pass http proxy in request call like this:

request({
  proxy: proxy_url
  url: url_to_reach
  .......
})

HTTP Proxy configuration is present in the http.properties file under apigee configuration:

apigee4/conf/apigee/message-processor/http.properties.

I want to read proxy url from this file and use it in node.js request call. Is it possible to get value of http proxy in node.js? May be it's already available in one of the flow / system / global variables?

I also tried using 'use.proxy' in httptargetconnection of target flow, but node.js runs as a separate javascript and target properties are not applicable there.

Please suggest.

Thanks.

2 5 7,515
5 REPLIES 5

Not applicable

Hi Mayank,

I understand that you want to use the flow variables from an Apigee proxy into your node.js implementation running as an apigee target, correct?

We have an NPM module to do exactly this, called - "Apigee access".

Check this out - https://www.npmjs.com/package/apigee-access

I believe this should work for you.

-Vinit

Hi Vinit,

Thanks for response.

I'm specifically looking to read http_proxy from http.properties file. I searched for this in flow variables, but I couldn't find where is it available, and under which name?

Can you please suggest?

Thanks.

Mayank,

I dont think you would be able to read from the file system through node.

What is it exactly that you want to be able to read through your node?

Like a http proxy name? some other aspect related to the proxy?

Check this page out and see if there is already an apigee variable set to read -

http://docs.apigee.com/api-services/reference/variables-reference

Once you see that there is a variable available in context of apigee request you can use the node module - apigee access to read it from your node.

-Vinit

Hi Vinit,

I've seen variables link earlier too, and checked it again as well. The variable I want to read is not present in the long list.

From my node.js code, I want to make an http request through a http proxy. This http proxy is configured in http.properties file present here : /home/apigee/apigee4/conf/apigee/message-processor/http.properties. Variable name is : HTTPClient.proxy.host, HTTPClient.proxy.port.

If I write a simple api proxy [not node.js based], then these settings are internally read by apigee and http request is proxied correctly.

However, for node.js based proxy, proxying of http request doesn't happen. In node.js code, proxy name has to be passed explicitly.

So, the question is: Is it possible to get above variables in node.js code?

We use on-premise version of apigee Version 4.15.07.03.

Hi Vinit,

I'm having the same problem with the same characteristics in an on-premise installation of ApiGee.

I'll try to explain better:

We have an ApiGee proxy that contains a node.js script;

On this node.js script we need to be able to do a web request to a given address, let's say to google.com;

As we are in a corporate on-premise installation, in order to make a web request from a node.js inside an ApiGee proxy we need to use a proxy (this is the real meaning of a proxy, it is a network proxy, not an ApiGee proxy);

If we were using a regular node.js application we could use something like that:

var http = require('http');

var req = http.request({
    host: '192.168.5.8', // here I put the proxy IP Address
    port: 8080, // Here I put the proxy port

    method: 'GET',
    path: 'https://www.google.com' // The url I want to access
    });
});

When using ApiGee, that may be deployed in multiple server, each one with it's specific proxy (or proxies), we cannot put the proxy IP hardcoded, we should use the proxy that is supposed to be used.

As stated by Mayank, the proxy is defined in "apigee-installation-folder/apigee4/conf/apigee/message-processor/http.properties" with the properties HTTPClient.proxy.host, HTTPClient.proxy.port.

The question is: How can we retrieve this proxy (network proxy, not ApiGee proxy) data inside a node script running in an ApiGee proxy?


So we could do something like this:

var http = require('http');

var proxyHost = // retrieve it somehow
var proxyPort = // retrieve it somehow var req = http.request({ host: proxyHost, // here I put the proxy IP Address port: proxyPort, // Here I put the proxy port method: 'GET', path: 'https://www.google.com' // The url I want to access }); });