Last active
October 10, 2016 00:39
-
-
Save jodevsa/7dd9662b8244359fa0d7626ae7c9bd69 to your computer and use it in GitHub Desktop.
simple request wrapper to add proxy settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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