Skip to content

fix: proxy support #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 <aohri@redhat.com>



# [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))
Expand Down
23 changes: 20 additions & 3 deletions app/chromeCache.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { HttpProxyAgent, HttpsProxyAgent } = require("hpagent");
const got = require("got");

const DEFAULT_CHROME_HOST = "https://access.redhat.com";
Expand Down Expand Up @@ -26,20 +27,23 @@ async function getParts({
path,
legacy,
locale,
conf,
});
const headerReq = fetchChromePart({
host,
part: "header",
path,
legacy,
locale,
conf,
});
const footerReq = fetchChromePart({
host,
part: "footer",
path,
legacy,
locale,
conf,
});

const [head, header, footer] = await Promise.all([
Expand 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}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions app/chromeMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function SPACommentResolver(conf) {
host,
legacy: true,
locale,
conf,
});

return data
Expand Down
13 changes: 11 additions & 2 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -45,7 +45,9 @@
"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",
"inquirer": "8.2.6",
"lodash": "4.17.21",
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down
Loading