Skip to content

Commit 7677bb2

Browse files
committed
add https proxy agent
add lib/fetch.js and lib/env.js replace use of node-fetch in download, scripts and src files
1 parent 6780179 commit 7677bb2

File tree

15 files changed

+79
-919
lines changed

15 files changed

+79
-919
lines changed

download/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import zlib from 'zlib'
88

99
// Packages
1010
import onDeath from 'death'
11-
import fetch from 'node-fetch'
1211
import retry from 'async-retry'
1312

1413
// Utilities
14+
import fetch from '../../lib/fetch'
1515
import plusxSync from './chmod'
1616
import {
1717
disableProgress,
@@ -21,7 +21,7 @@ import {
2121
warn
2222
} from './log'
2323

24-
fetch.Promise = Promise
24+
fetch.originalFetch.Promise = Promise
2525
global.Promise = Promise
2626
let { platform } = process
2727
if (detectAlpine()) platform = 'alpine'

lib/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (envString, defaultValue) => {
2+
return process.env[envString] || defaultValue
3+
}

lib/fetch.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const fetch = require('node-fetch')
2+
const ProxyAgent = require('https-proxy-agent')
3+
4+
const env = require('./env')
5+
6+
const proxy = env('https_proxy')
7+
|| env('HTTPS_PROXY')
8+
|| env('http_proxy')
9+
|| env('HTTP_PROXY')
10+
const agent = proxy ? new ProxyAgent(proxy) : undefined
11+
12+
exports = module.exports = (url, options = {}) => {
13+
return fetch(url, Object.assign(options, {agent}))
14+
}
15+
16+
exports.originalFetch = fetch

0 commit comments

Comments
 (0)