From d08832f8cfc593e1d62f45ade7840b5077a172fc Mon Sep 17 00:00:00 2001 From: Michael Clayton Date: Mon, 10 Mar 2025 15:01:48 -0400 Subject: [PATCH 1/2] fix: proxy support --- app/chromeCache.js | 23 ++++++++++++++++++++--- app/chromeMiddleware.js | 1 + app/router.js | 13 +++++++++++-- package.json | 2 ++ yarn.lock | 7 ++++++- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/chromeCache.js b/app/chromeCache.js index 94166abb..93be4fb3 100644 --- a/app/chromeCache.js +++ b/app/chromeCache.js @@ -1,3 +1,4 @@ +const { HttpProxyAgent, HttpsProxyAgent } = require("hpagent"); const got = require("got"); const DEFAULT_CHROME_HOST = "https://access.redhat.com"; @@ -26,6 +27,7 @@ async function getParts({ path, legacy, locale, + conf, }); const headerReq = fetchChromePart({ host, @@ -33,6 +35,7 @@ async function getParts({ path, legacy, locale, + conf, }); const footerReq = fetchChromePart({ host, @@ -40,6 +43,7 @@ async function getParts({ path, legacy, locale, + conf, }); const [head, header, footer] = await Promise.all([ @@ -65,17 +69,30 @@ async function fetchChromePart({ part, legacy = false, locale = "en", + conf, } = {}) { - const url = `${host}${path}${part}/${locale}${ + const url = `${host}${path}${part}/${locale}/${ legacy ? "?legacy=false" : "" }`; console.log(`fetching chrome from ${url}`); + let options = {}; + + if (host.startsWith("https:")) { + options.agent = { + https: new HttpsProxyAgent({ proxy: conf.proxy.host }), + }; + } else if (host.startsWith("http:")) { + options.agent = { + http: new HttpProxyAgent({ proxy: conf.proxy.host }), + }; + } + try { - const res = await got(url); + const res = await got(url, options); return res.body; } catch (e) { - console.error(`attempting to fetch ${url} failed`); + console.error(`attempting to fetch ${url} failed: ${e}`); } } diff --git a/app/chromeMiddleware.js b/app/chromeMiddleware.js index 783e2eea..f8446fc7 100644 --- a/app/chromeMiddleware.js +++ b/app/chromeMiddleware.js @@ -16,6 +16,7 @@ function SPACommentResolver(conf) { host, legacy: true, locale, + conf, }); return data diff --git a/app/router.js b/app/router.js index bc668878..7e7c530c 100644 --- a/app/router.js +++ b/app/router.js @@ -7,7 +7,8 @@ const { flow, includes, get } = require("lodash/fp"); const finalhandler = require("finalhandler"); const serveStatic = require("serve-static"); const resolveHome = require("./resolveHome"); -const ProxyAgent = require("proxy-agent"); +const HttpsProxyAgent = require("https-proxy-agent"); +const HttpProxyAgent = require("http-proxy-agent"); const priv = {}; priv.tryPlugin = (plugin, req, res, target, cb) => { @@ -38,7 +39,15 @@ priv.doProxy = (proxy, req, res, target, confProxy = null) => { // pattern provided in the proxy.pattern property, // add a new HttpsProxyAgent if (regex.test(target)) { - options.agent = new ProxyAgent.ProxyAgent(confProxy.host); + if (target.startsWith("https:")) { + options.agent = new HttpsProxyAgent.HttpsProxyAgent( + confProxy.host + ); + } else if (target.startsWith("http:")) { + options.agent = new HttpProxyAgent.HttpProxyAgent( + confProxy.host + ); + } } } diff --git a/package.json b/package.json index 222c22d0..afc904ca 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "got": "11.8.3", "hostile": "1.3.3", "http-proxy": "1.18.1", + "http-proxy-agent": "7.0.0", "https-proxy-agent": "7.0.0", "inquirer": "8.2.6", "lodash": "4.17.21", @@ -56,6 +57,7 @@ "proxy-agent": "6.2.1", "serve-static": "1.15.0", "transformer-proxy": "0.3.5", + "hpagent": "1.2.0", "yargs": "17.4.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index bb195005..1ee11e9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2207,6 +2207,11 @@ hostile@1.3.3: split "^1.0.1" through "^2.3.8" +hpagent@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-1.2.0.tgz#0ae417895430eb3770c03443456b8d90ca464903" + integrity sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA== + html-encoding-sniffer@^3.0.0: version "3.0.0" 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: setprototypeof "1.1.0" statuses ">= 1.4.0 < 2" -http-proxy-agent@^7.0.0: +http-proxy-agent@7.0.0, http-proxy-agent@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz#e9096c5afd071a3fce56e6252bb321583c124673" integrity sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ== From b6946b9333d9352e33d17102ca233c4ad523e601 Mon Sep 17 00:00:00 2001 From: Michael Clayton Date: Mon, 10 Mar 2025 15:14:25 -0400 Subject: [PATCH 2/2] v3.1.0-prerelease.0 --- CHANGELOG.md | 24 ++++++++++++++++++++++++ package.json | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13cad3d..78189544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# [3.1.0-prerelease.0](https://github.com/redhataccess/spandx/compare/v2.2.7...v3.1.0-prerelease.0) (2025-03-10) + + +### Bug Fixes + +* proxy support ([d08832f](https://github.com/redhataccess/spandx/commit/d08832f8cfc593e1d62f45ade7840b5077a172fc)) + + +* test!: remove support for node 16 (#347) ([111e79a](https://github.com/redhataccess/spandx/commit/111e79a409a43de55962e94ed08752f68cbc9d0c)), closes [#347](https://github.com/redhataccess/spandx/issues/347) + + +### Features + +* apply localized primer/chrome based on rh_locale cookie ([86dff14](https://github.com/redhataccess/spandx/commit/86dff145dca27689782068d4c44a6b05a5f739b2)) + + +### BREAKING CHANGES + +* remove support for node 16 + +Co-authored-by: Aditi Ohri + + + # [3.0.0](https://github.com/redhataccess/spandx/compare/v2.2.7...v3.0.0) (2023-10-23) * test!: remove support for node 16 ([111e79a](https://github.com/redhataccess/spandx/commit/111e79a409a43de55962e94ed08752f68cbc9d0c)) diff --git a/package.json b/package.json index afc904ca..bfab1c3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spandx", - "version": "3.0.0", + "version": "3.1.0-prerelease.0", "description": "Develop locally, proxy to prod, browser-sync, inject Portal Chrome.", "main": "app/spandx.js", "bin": "app/cli.js", @@ -45,6 +45,7 @@ "finalhandler": "1.2.0", "got": "11.8.3", "hostile": "1.3.3", + "hpagent": "1.2.0", "http-proxy": "1.18.1", "http-proxy-agent": "7.0.0", "https-proxy-agent": "7.0.0", @@ -57,7 +58,6 @@ "proxy-agent": "6.2.1", "serve-static": "1.15.0", "transformer-proxy": "0.3.5", - "hpagent": "1.2.0", "yargs": "17.4.1" }, "devDependencies": {