From 6c72eea4066f31656214ccc45515e0ce0a97dd8a Mon Sep 17 00:00:00 2001 From: Christopher Heschong Date: Wed, 17 Aug 2022 16:41:17 -0400 Subject: [PATCH] Add https proxy support --- npm-packages/meteor-installer/README.md | 5 +++++ npm-packages/meteor-installer/install.js | 13 +++++++++++++ npm-packages/meteor-installer/package.json | 1 + 3 files changed, 19 insertions(+) diff --git a/npm-packages/meteor-installer/README.md b/npm-packages/meteor-installer/README.md index 9ab8a2de6a..2d74de733a 100644 --- a/npm-packages/meteor-installer/README.md +++ b/npm-packages/meteor-installer/README.md @@ -52,3 +52,8 @@ npm install -g meteor --ignore-meteor-setup-exec-path ``` (or by setting the environment variable `npm_config_ignore_meteor_setup_exec_path=true`) + +### Proxy configuration + +Setting the `https_proxy` or `HTTPS_PROXY` environment variable to a valid proxy URL will cause the +downloader to use the configured proxy to retrieve the Meteor files. \ No newline at end of file diff --git a/npm-packages/meteor-installer/install.js b/npm-packages/meteor-installer/install.js index 25b252a525..f52fd003f2 100644 --- a/npm-packages/meteor-installer/install.js +++ b/npm-packages/meteor-installer/install.js @@ -1,4 +1,5 @@ const { DownloaderHelper } = require('node-downloader-helper'); +const HttpsProxyAgent = require('https-proxy-agent'); const cliProgress = require('cli-progress'); const Seven = require('node-7z'); const path = require('path'); @@ -133,6 +134,15 @@ try { download(); +function generateProxyAgent() { + const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY; + if (!proxyUrl) { + return undefined; + } + + return new HttpsProxyAgent(proxyUrl); +} + function download() { const start = Date.now(); const downloadProgress = new cliProgress.SingleBar( @@ -148,6 +158,9 @@ function download() { retry: { maxRetries: 5, delay: 5000 }, override: true, fileName: tarGzName, + httpsRequestOptions: { + agent: generateProxyAgent() + } }); dl.on('progress', ({ progress }) => { diff --git a/npm-packages/meteor-installer/package.json b/npm-packages/meteor-installer/package.json index 9ca969a6c6..4e716a5acf 100644 --- a/npm-packages/meteor-installer/package.json +++ b/npm-packages/meteor-installer/package.json @@ -11,6 +11,7 @@ "dependencies": { "7zip-bin": "^5.0.3", "cli-progress": "^3.5.0", + "https-proxy-agent": "^5.0.1", "node-7z": "^2.0.5", "node-downloader-helper": "^1.0.11", "rimraf": "^3.0.2",