github icon indicating copy to clipboard operation
github copied to clipboard

How to use the API through a Proxy?

Open ArnaudBuchholz opened this issue 8 years ago • 3 comments

This may sound like a stupid question but I can't make it work behind a proxy. What is the procedure to configure proxy information? Should it be done through NodeJS? (I tried to configure axios default to setup the proxy but it does not seem to work)

Thanks,

  • Arnaud

ArnaudBuchholz avatar Feb 28 '17 03:02 ArnaudBuchholz

Same Problem here.

vitorcominato avatar Oct 13 '17 14:10 vitorcominato

Also running into the same issue. I forked the repo and added the following to lib/Requestable.js:

const URLParse = require('url-parse');
const HttpsProxyAgent = require('https-proxy-agent');

// ...
// in `_request`, where const config is defined
      const config = {
         url: url,
         method: method,
         headers: headers,
         params: queryParams,
         data: data,
         responseType: raw ? 'text' : 'json',
      };

      //add proper support for proxy
      if (process.env.https_proxy) {
         var parsedUrl = URLParse(process.env.https_proxy);
         var agent = new HttpsProxyAgent(parsedUrl.origin);

         config.httpsAgent = agent;
         config.proxy = false;
      }

FYI this code does NOT cover all edge cases and I haven't created any unit tests for this, but it's working on my side as long as the https_proxy environment variable is set. Also, it currently doesn't support user/password auth which will be a requirement for some others.

https://github.com/mm-gmbd/github/releases/tag/v3.3.1 (you can include the following in your package.json):

  "dependencies": {
    "github-api": "git+https://github.com/mm-gmbd/github.git#v3.3.1",
   }

Has the above code "released".

mm-gmbd avatar Feb 11 '20 16:02 mm-gmbd

Also, the current code I've got for this is on my forked repo feature branch feature/proxy-support.

mm-gmbd avatar Feb 11 '20 16:02 mm-gmbd