Skip to content

Commit e7fee41

Browse files
committed
fix: Update command does not work with proxy
1 parent cb63e51 commit e7fee41

File tree

3 files changed

+136
-54
lines changed

3 files changed

+136
-54
lines changed

lib/remote.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
const unzip = require('node-unzip-2');
44
const config = require('./config');
5-
const axios = require('axios');
5+
const fetch = require('node-fetch');
6+
const { HttpsProxyAgent } = require('https-proxy-agent');
7+
const { getProxyForUrl } = require('proxy-from-env');
68

79
// Downloads the zip file from github and extracts it to folder
810
exports.download = (path) => {
@@ -11,13 +13,16 @@ exports.download = (path) => {
1113
// Creating the extractor
1214
const extractor = unzip.Extract({ path });
1315

14-
let req = axios({
15-
method: 'get',
16-
url: url,
17-
responseType: 'stream',
18-
headers: { 'User-Agent' : 'tldr-node-client' }
19-
}).then(function (response) {
20-
response.data.pipe(extractor);
16+
const headers = { 'User-Agent' : 'tldr-node-client' };
17+
const fetchOptions = { headers };
18+
19+
const proxy = getProxyForUrl(url);
20+
if (proxy) {
21+
fetchOptions.agent = new HttpsProxyAgent(proxy, { headers });
22+
}
23+
24+
const req = fetch(url, fetchOptions).then((res) => {
25+
res.body.pipe(extractor);
2126
});
2227

2328
return new Promise((resolve, reject) => {

package-lock.json

+119-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@
5050
"test:all": "npm run lint && npm test && npm run test:functional"
5151
},
5252
"dependencies": {
53-
"axios": "^0.21.1",
5453
"chalk": "^4.1.0",
5554
"commander": "^6.1.0",
5655
"fs-extra": "^9.0.1",
5756
"glob": "^7.1.6",
57+
"https-proxy-agent": "^7.0.2",
5858
"lodash": "^4.17.20",
5959
"marked": "^4.0.10",
6060
"ms": "^2.1.2",
6161
"natural": "^2.1.5",
62+
"node-fetch": "^2.7.0",
6263
"node-unzip-2": "^0.2.8",
63-
"ora": "^5.1.0"
64+
"ora": "^5.1.0",
65+
"proxy-from-env": "^1.1.0"
6466
},
6567
"devDependencies": {
6668
"eslint": "^8.39.0",

0 commit comments

Comments
 (0)