Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createProxyAgent(url) {
// Determine environemt variable names to search for
const {protocol} = parse(url);
const protocolName = protocol.replace(':', '');
const envNames = [
`${protocolName}_proxy`,
`${protocolName}_proxy`.toUpperCase()
];
// Check if proxy is configured for current url protocol
const enabled = envNames.find(envName => process.env[envName]);
// Return suitable proxy agent, null of none configured
return enabled ? caw({protocol: protocolName}) : null;
}