You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 734B

123456789101112131415161718192021222324
  1. const superagent = require('superagent');
  2. const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
  3. // extend with Request#proxy()
  4. require('superagent-proxy')(superagent);
  5. module.exports = (remoteUrl, callback) => {
  6. const proxyUrl = getProxyForUrl(remoteUrl);
  7. const superagentCallback = (err, resp) => {
  8. if (err) {
  9. return callback(err);
  10. } else if (resp.ok) {
  11. return callback(null, resp.text);
  12. }
  13. return callback(new Error(`GET ${remoteUrl} ${resp.status}`));
  14. };
  15. if (proxyUrl) {
  16. superagent.get(remoteUrl).proxy(proxyUrl).buffer().end(superagentCallback);
  17. } else {
  18. superagent.get(remoteUrl).buffer().end(superagentCallback);
  19. }
  20. };