node-get-url-proxy
get-url-proxy
will return the applicable proxy to use for a given URL based on NO_PROXY
and {PROTOCOL}_PROXY
environment variables.
console // "http://proxy:8080/"console; // ".foo.com,192.168.1." // requires protocol & domainvar getProxy = ;; // null; // "http://proxy:8080/" // the cached wrapper will cache the last 100 resourcesvar cachedProxy = ; // protocol only, without NO_PROXY checkvar protocolProxy = ;: // "http://proxy:8080/"
Search Order
The following search order will be used, generally speaking...
NO_PROXY
exclusion will returnnull
PROTOCOL_PROXY
protocol_proxy
ALL_PROXY
all_proxy
null
will be returned with no match.
Web protocols
For web based protocols, additional/similar protocols will be searched as a fallback.
HTTP
-> [HTTP
,HTTPS
]HTTPS
-> [HTTPS
,HTTP
]WS
-> [WS
,WSS
,HTTPS
,HTTP
]WSS
-> [WSS
,WS
,HTTPS
,HTTP
]SFTP
-> [SFTP
,SSH
]
All other protocols will only search for their own protocol specifically, falling back to ALL_PROXY
NOTE: You may want to use memoization around this module.
WARNING
If you are using a node version prior to Node 8, you should install url-parse
as a dependency.