proxy.js 1.3 KB

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