Skip to content

Commit d08832f

Browse files
committed
fix: proxy support
1 parent dc39071 commit d08832f

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

app/chromeCache.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { HttpProxyAgent, HttpsProxyAgent } = require("hpagent");
12
const got = require("got");
23

34
const DEFAULT_CHROME_HOST = "https://access.redhat.com";
@@ -26,20 +27,23 @@ async function getParts({
2627
path,
2728
legacy,
2829
locale,
30+
conf,
2931
});
3032
const headerReq = fetchChromePart({
3133
host,
3234
part: "header",
3335
path,
3436
legacy,
3537
locale,
38+
conf,
3639
});
3740
const footerReq = fetchChromePart({
3841
host,
3942
part: "footer",
4043
path,
4144
legacy,
4245
locale,
46+
conf,
4347
});
4448

4549
const [head, header, footer] = await Promise.all([
@@ -65,17 +69,30 @@ async function fetchChromePart({
6569
part,
6670
legacy = false,
6771
locale = "en",
72+
conf,
6873
} = {}) {
69-
const url = `${host}${path}${part}/${locale}${
74+
const url = `${host}${path}${part}/${locale}/${
7075
legacy ? "?legacy=false" : ""
7176
}`;
7277
console.log(`fetching chrome from ${url}`);
7378

79+
let options = {};
80+
81+
if (host.startsWith("https:")) {
82+
options.agent = {
83+
https: new HttpsProxyAgent({ proxy: conf.proxy.host }),
84+
};
85+
} else if (host.startsWith("http:")) {
86+
options.agent = {
87+
http: new HttpProxyAgent({ proxy: conf.proxy.host }),
88+
};
89+
}
90+
7491
try {
75-
const res = await got(url);
92+
const res = await got(url, options);
7693
return res.body;
7794
} catch (e) {
78-
console.error(`attempting to fetch ${url} failed`);
95+
console.error(`attempting to fetch ${url} failed: ${e}`);
7996
}
8097
}
8198

app/chromeMiddleware.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function SPACommentResolver(conf) {
1616
host,
1717
legacy: true,
1818
locale,
19+
conf,
1920
});
2021

2122
return data

app/router.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const { flow, includes, get } = require("lodash/fp");
77
const finalhandler = require("finalhandler");
88
const serveStatic = require("serve-static");
99
const resolveHome = require("./resolveHome");
10-
const ProxyAgent = require("proxy-agent");
10+
const HttpsProxyAgent = require("https-proxy-agent");
11+
const HttpProxyAgent = require("http-proxy-agent");
1112
const priv = {};
1213

1314
priv.tryPlugin = (plugin, req, res, target, cb) => {
@@ -38,7 +39,15 @@ priv.doProxy = (proxy, req, res, target, confProxy = null) => {
3839
// pattern provided in the proxy.pattern property,
3940
// add a new HttpsProxyAgent
4041
if (regex.test(target)) {
41-
options.agent = new ProxyAgent.ProxyAgent(confProxy.host);
42+
if (target.startsWith("https:")) {
43+
options.agent = new HttpsProxyAgent.HttpsProxyAgent(
44+
confProxy.host
45+
);
46+
} else if (target.startsWith("http:")) {
47+
options.agent = new HttpProxyAgent.HttpProxyAgent(
48+
confProxy.host
49+
);
50+
}
4251
}
4352
}
4453

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"got": "11.8.3",
4747
"hostile": "1.3.3",
4848
"http-proxy": "1.18.1",
49+
"http-proxy-agent": "7.0.0",
4950
"https-proxy-agent": "7.0.0",
5051
"inquirer": "8.2.6",
5152
"lodash": "4.17.21",
@@ -56,6 +57,7 @@
5657
"proxy-agent": "6.2.1",
5758
"serve-static": "1.15.0",
5859
"transformer-proxy": "0.3.5",
60+
"hpagent": "1.2.0",
5961
"yargs": "17.4.1"
6062
},
6163
"devDependencies": {

yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,11 @@ hostile@1.3.3:
22072207
split "^1.0.1"
22082208
through "^2.3.8"
22092209

2210+
hpagent@1.2.0:
2211+
version "1.2.0"
2212+
resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-1.2.0.tgz#0ae417895430eb3770c03443456b8d90ca464903"
2213+
integrity sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA==
2214+
22102215
html-encoding-sniffer@^3.0.0:
22112216
version "3.0.0"
22122217
resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz#2cb1a8cf0db52414776e5b2a7a04d5dd98158de9"
@@ -2240,7 +2245,7 @@ http-errors@~1.6.2:
22402245
setprototypeof "1.1.0"
22412246
statuses ">= 1.4.0 < 2"
22422247

2243-
http-proxy-agent@^7.0.0:
2248+
http-proxy-agent@7.0.0, http-proxy-agent@^7.0.0:
22442249
version "7.0.0"
22452250
resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz#e9096c5afd071a3fce56e6252bb321583c124673"
22462251
integrity sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==

0 commit comments

Comments
 (0)