Accessing an HTTPS Service from Node.js

    We recommend the https-proxy-agent library for carrying out HTTP operations from Node.js with XLRoutes.

    Installation

    When you sign up with XLRoutes, you will be provided with a unique username and password and a connection string that you can use when configuring your proxy service in your application, for example:

    http://username:password@static-proxy.xlroutes.com:9293
    

    All requests that you make via this proxy will appear to the destination server to originate from one of the two static IPs you will be assigned when you sign up.

    We recommend you store the connection string in an environment variable xlroutes_URL. If you have signed up via the add-ons platform on Heroku or cloudControl this variable will be automatically set in your production environment.

    Integration

    XLRoutes will work with the standard http library, but we recommend using the https-proxy-agent library for ease of use.

    var HttpsProxyAgent = require('https-proxy-agent');
    var request = require('request');
    var proxy = process.env.xlroutesSTATIC_URL;
    var agent = new HttpsProxyAgent(proxy);
    request({
      uri: "https://example.com/api",
      method: "POST",
      headers: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      agent: agent,
      timeout: 10000,
      followRedirect: true,
      maxRedirects: 10,
      body: "name=john"
    }, function(error, response, body) {
      console.log("Error" + error);
      console.log("Response: " + response);
      console.log("Body: " + body);
    });
    

    Other Libraries

    We have examples for other common libraries as well, but if you can’t find what you are looking for just send us a Support ticket and we’ll get one sent to you.