UNPKG

1.21 kBJavaScriptView Raw
1import * as debug from 'debug';
2import { getEnv, setEnv } from './utils';
3const d = debug('@electron/get:proxy');
4/**
5 * Initializes a third-party proxy module for HTTP(S) requests.
6 */
7export function initializeProxy() {
8 try {
9 // Code originally from https://github.com/yeoman/yo/blob/b2eea87e/lib/cli.js#L19-L28
10 const MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);
11 if (MAJOR_NODEJS_VERSION >= 10) {
12 // See: https://github.com/electron/get/pull/214#discussion_r798845713
13 const env = getEnv('GLOBAL_AGENT_');
14 setEnv('GLOBAL_AGENT_HTTP_PROXY', env('HTTP_PROXY'));
15 setEnv('GLOBAL_AGENT_HTTPS_PROXY', env('HTTPS_PROXY'));
16 setEnv('GLOBAL_AGENT_NO_PROXY', env('NO_PROXY'));
17 // `global-agent` works with Node.js v10 and above.
18 require('global-agent').bootstrap();
19 }
20 else {
21 // `global-tunnel-ng` works with Node.js v10 and below.
22 require('global-tunnel-ng').initialize();
23 }
24 }
25 catch (e) {
26 d('Could not load either proxy modules, built-in proxy support not available:', e);
27 }
28}
29//# sourceMappingURL=proxy.js.map
\No newline at end of file