forked from backstage/backstage
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request backstage#28529 from backstage/freben/proxy-doc
update the corp proxy doc too
- Loading branch information
Showing
3 changed files
with
21 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,43 +22,27 @@ There are however some ways to get this to work without too much effort. | |
|
||
`undici` exposes the settings for native `fetch`, and `global-agent` can set things up for `node-fetch`. | ||
|
||
1. Go to the entry file for the backend (typically `packages/backend/src/index.ts`), and add the following at the top: | ||
1. Go to the entry file for the backend (typically `packages/backend/src/index.ts`), and add the following at the VERY top, before all other imports etc: | ||
|
||
```ts | ||
import 'global-agent/bootstrap'; | ||
import { setGlobalDispatcher, ProxyAgent } from 'undici'; | ||
|
||
const proxyEnv = | ||
process.env.GLOBAL_AGENT_HTTP_PROXY || | ||
process.env.GLOBAL_AGENT_HTTPS_PROXY; | ||
|
||
if (proxyEnv) { | ||
const proxyUrl = new URL(proxyEnv); | ||
setGlobalDispatcher( | ||
new ProxyAgent({ | ||
uri: proxyUrl.protocol + proxyUrl.host, | ||
token: | ||
proxyUrl.username && proxyUrl.password | ||
? `Basic ${Buffer.from( | ||
`${proxyUrl.username}:${proxyUrl.password}`, | ||
).toString('base64')}` | ||
: undefined, | ||
}), | ||
); | ||
} | ||
``` | ||
import { setGlobalDispatcher, EnvHttpProxyAgent } from 'undici'; | ||
|
||
The first import automatically bootstraps `global-agent`, which addresses `node-fetch` proxying. The lines of code below that peeks into the same environment variables as `global-agent` uses, and also leverages them to set up the `undici` package which affects native `fetch`. Does that seem weird? Yes, we think so too. But in the current state of the Node.js ecosystem, that's how it works. | ||
setGlobalDispatcher(new EnvHttpProxyAgent()); | ||
``` | ||
|
||
This code is kept brief for illustrative purposes. You may want to adjust it slightly if you need support for [no-proxy excludes](https://gist.github.com/zicklag/1bb50db6c5138de347c224fda14286da) or only do proxying in local development etc. Also see [the `global-agent` docs](https://github.com/gajus/global-agent) for information about its configuration options. | ||
The first import automatically bootstraps `global-agent`, which addresses `node-fetch` proxying. The lines below that set up the `undici` package which affects native `fetch`. | ||
|
||
1. Start the backend with the correct environment variables set. For example: | ||
|
||
```sh | ||
export GLOBAL_AGENT_HTTP_PROXY=http://username:[email protected]:8888 | ||
export HTTP_PROXY=http://username:[email protected]:8888 | ||
export GLOBAL_AGENT_HTTP_PROXY=${HTTP_PROXY} | ||
yarn start | ||
``` | ||
|
||
The default for `global-agent` is to have a prefix on the variable names, hence the need for specifying it twice. | ||
|
||
## Configuration | ||
|
||
If your development environment is in the cloud (like with [AWS Cloud9](https://aws.amazon.com/cloud9/) or an instance of [Theia](https://theia-ide.org/)), you will need to update your configuration. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters