global-proxy-agent
Version:
A universal proxy agent for Node.js that combines environment-variable-based proxy resolution with smart protocol-aware agent selection. Automatically supports HTTP, HTTPS, SOCKS, and PAC proxies using a modular, runtime-configurable approach. It also pro
29 lines (28 loc) • 1.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupGlobalProxyAgent = setupGlobalProxyAgent;
const createSmartProxyAgent_1 = require("./agent/createSmartProxyAgent");
const env_1 = require("./config/env");
const logger_1 = require("./config/logger");
const state_1 = require("./config/state");
const exclude_1 = require("./utils/exclude");
function setupGlobalProxyAgent(options = {}) {
const { envNamespace = 'GLOBAL_AGENT_', forceGlobal = true, timeout = 60000, logging = false, exclude = [], fallbackProxies = [], } = options;
(0, env_1.setEnvProxyConfig)(envNamespace);
if (exclude.length)
(0, exclude_1.setGlobalNoProxy)(exclude);
const agent = (0, createSmartProxyAgent_1.createSmartProxyAgent)({ timeout });
// globalState.setAgent(agent);
state_1.globalState.agent = agent;
state_1.globalState.proxyUrl = process.env[`${envNamespace}HTTP_PROXY`] || '';
state_1.globalState.forceGlobal = forceGlobal;
state_1.globalState.exclude = exclude;
state_1.globalState.logging = logging;
state_1.globalState.fallbackProxies = fallbackProxies;
if (forceGlobal) {
require('http').globalAgent = agent;
require('https').globalAgent = agent;
}
if (logging)
logger_1.logger.info('Global proxy agent set up.');
}
;