Fix: Set https proxy for npm cli install script
const fs = require('fs');
const zlib = require('zlib');
+const http = require('http');
const https = require('https');
const packageJSON = require('./package.json');
@@ -64,7 +65,25 @@ file.on('finish', () => {
// Follow redirects.
function get(url, callback) {
- https.get(url, response => {
+ const requestUrl = new URL(url)
+ let request = https
+ let requestConfig = requestUrl
+ const proxyEnv = process.env['HTTPS_PROXY'] || process.env['https_proxy']
+
+ if (proxyEnv) {
+ const proxyUrl = new URL(proxyEnv)
+ request = proxyUrl.protocol === 'https:' ? https : http
+ requestConfig = {
+ hostname: proxyUrl.hostname,
+ port: proxyUrl.port,
+ path: requestUrl.toString(),
+ headers: {
+ Host: requestUrl.hostname
+ }
+ }
+ }
+
+ request.get(requestConfig, response => {
if (response.statusCode === 301 || response.statusCode === 302) {
get(response.headers.location, callback);
} else {
