Skip to content

Instantly share code, notes, and snippets.

@jodevsa
Last active October 10, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodevsa/7dd9662b8244359fa0d7626ae7c9bd69 to your computer and use it in GitHub Desktop.
Save jodevsa/7dd9662b8244359fa0d7626ae7c9bd69 to your computer and use it in GitHub Desktop.
simple request wrapper to add proxy settings
//rename index.js file to core.js
//and create a new index.js with this content
const request=require('./core.js');
/////////////////////////////
//enable/disable wrapper
const ON=true;
//proxy settings
const proxyLoc='http://localhost:8080';
/////////////////////////////
function requestWrapper(uri, options, callback){
request.defaults({'proxy':proxyLoc})(uri,options,callback);
}
requestWrapper.defaults=function (options,requester){
if (typeof options === 'function') {
requester=options;
options={'proxy':proxyLoc};
}
else{
options.proxy=proxyLoc;
}
return request.defaults(options,requester);
}
module.exports=(ON)?requestWrapper:request;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment