UNPKG

os-proxy-config

Version:

Access the operating system proxy configuration from Node.js, for all platforms

61 lines 2.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSystemProxy = void 0; const windows_system_proxy_1 = require("windows-system-proxy"); const mac_system_proxy_1 = require("mac-system-proxy"); function getSystemProxy() { return __awaiter(this, void 0, void 0, function* () { if (process.platform === 'win32') { return (0, windows_system_proxy_1.getWindowsSystemProxy)(); } else if (process.platform === 'darwin') { const proxySettings = yield (0, mac_system_proxy_1.getMacSystemProxy)(); const noProxy = proxySettings.ExceptionsList || []; if (proxySettings.HTTPEnable && proxySettings.HTTPProxy && proxySettings.HTTPPort) { return { proxyUrl: `http://${proxySettings.HTTPProxy}:${proxySettings.HTTPPort}`, noProxy }; } else if (proxySettings.SOCKSEnable && proxySettings.SOCKSProxy && proxySettings.SOCKSPort) { return { proxyUrl: `socks://${proxySettings.SOCKSProxy}:${proxySettings.SOCKSPort}`, noProxy }; } else if (proxySettings.HTTPSEnable && proxySettings.HTTPSProxy && proxySettings.HTTPSPort) { return { proxyUrl: `http://${proxySettings.HTTPSProxy}:${proxySettings.HTTPSPort}`, noProxy }; } else { return undefined; } } else { const { HTTPS_PROXY, https_proxy, HTTP_PROXY, http_proxy, NO_PROXY, no_proxy } = process.env; const proxyUrl = HTTPS_PROXY || HTTP_PROXY || https_proxy || http_proxy; if (!proxyUrl) return undefined; const noProxy = !!(NO_PROXY || no_proxy) ? (NO_PROXY || no_proxy).split(',') : []; return { proxyUrl, noProxy }; } }); } exports.getSystemProxy = getSystemProxy; //# sourceMappingURL=index.js.map