Skip to content

Commit

Permalink
fix(proxy): use systemwide proxy while proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
redallen committed Jul 22, 2021
1 parent 5577c33 commit 53fe5c4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
12 changes: 5 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions packages/config-utils/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Webpack proxy and express config for `useProxy: true` or `standalone: true`
const { execSync } = require('child_process');
const path = require('path');
const HttpsProxyAgent = require('https-proxy-agent');
const cookieTransform = require('./cookieTransform');
const router = require('./standalone/helpers/router');
const { getConfig, isGitUrl, getExposedPort, resolvePath } = require('./standalone/helpers/index');
Expand All @@ -19,6 +20,7 @@ module.exports = ({
routes,
routesPath,
useProxy,
proxyURL = 'http://squid.corp.redhat.com:3128',
standalone,
port,
reposDir = defaultReposDir,
Expand Down Expand Up @@ -48,10 +50,13 @@ module.exports = ({

console.log('Proxing to', target);

let agent;
if (env.startsWith('stage')) {
// stage-stable / stage-beta branches don't exist in build repos
// Currently stage pulls from QA
env = env.replace('stage', 'qa');
// QA and stage are deployed with Akamai which requires a corporate proxy
agent = new HttpsProxyAgent(proxyURL);
}

if (!Array.isArray(appUrl)) {
Expand Down Expand Up @@ -80,7 +85,8 @@ module.exports = ({
ws: true,
onProxyReq: cookieTransform,
...(currTarget === 'PORTAL_BACKEND_MARKER' && { router }),
...typeof redirect === 'object' ? redirect : {}
...typeof redirect === 'object' ? redirect : {},
...(agent && { agent })
};
})
);
Expand Down Expand Up @@ -170,7 +176,8 @@ module.exports = ({
return false;
},
target,
router: router(target, useCloud)
router: router(target, useCloud),
...(agent && { agent })
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const { config: webpackConfig, plugins } = config({
|Attribute|Type|Description|
|---------|----|-----------|
|[useProxy](#useproxy)|`boolean`|Enables webpack proxy.|
|[proxyURL](#proxyURL)|`string`|URL to proxy Akamai environment requests to.|
|[localChrome](#localChrome)|`string`|Path to your local chrome build folder.|
|[registry](#registry)|`(({ app, server, compiler, standaloneConfig }) => void)[]`|Express middleware to register.|
|[routes](#routes)|`object`|An object with additional routes.|
Expand Down
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"glob": "^7.0.0",
"html-replace-webpack-plugin": "^2.6.0",
"html-webpack-plugin": "^5.3.1",
"https-proxy-agent": "^5.0.0",
"mini-css-extract-plugin": "^1.6.0",
"js-yaml": "^4.0.0",
"jws": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = ({
sassPrefix,
skipChrome2 = false,
useProxy,
proxyURL,
localChrome,
customProxy,
routes,
Expand Down Expand Up @@ -187,6 +188,7 @@ module.exports = ({
routes,
routesPath,
useProxy,
proxyURL,
standalone,
port: devServerPort,
reposDir,
Expand Down

0 comments on commit 53fe5c4

Please sign in to comment.