SGAF
|
Global HTTP/HTTPS proxy configurable using environment variables.
global-agent/bootstrap
To configure HTTP proxy:
global-agent/bootstrap
.GLOBAL_AGENT_HTTP_PROXY
environment variable.Code:
Bash:
Alternatively, you can preload module using Node.js --require, -r
configuration, e.g.
bootstrap
routineInstead of importing a self-initialising script with side-effects as demonstrated in the setup proxy using global-agent/bootstrap
documentation, you can import bootstrap
routine and explicitly evaluate the bootstrap logic, e.g.
This is useful if you need to conditionally bootstrap global-agent
, e.g.
createGlobalProxyAgent
If you do not want to use global.GLOBAL_AGENT
variable, then you can use createGlobalProxyAgent
to instantiate a controlled instance of global-agent
, e.g.
Unlike bootstrap
routine, createGlobalProxyAgent
factory does not create global.GLOBAL_AGENT
variable and does not guard against multiple initializations of global-agent
. The result object of createGlobalProxyAgent
is equivalent to global.GLOBAL_AGENT
.
global-agent/bootstrap
script copies process.env.GLOBAL_AGENT_HTTP_PROXY
value to global.GLOBAL_AGENT.HTTP_PROXY
and continues to use the latter variable.
You can override the global.GLOBAL_AGENT.HTTP_PROXY
value at runtime to change proxy behaviour, e.g.
The first HTTP request is going to use http://127.0.0.1:8001 proxy and the secord request is going to use http://127.0.0.1:8002.
All global-agent
configuration is available under global.GLOBAL_AGENT
namespace.
The GLOBAL_AGENT_NO_PROXY
environment variable specifies a pattern of URLs that should be excluded from proxying. GLOBAL_AGENT_NO_PROXY
value is a comma-separated list of domain names. Asterisks can be used as wildcards, e.g.
says to contact all machines with the 'foo.com' TLD and 'baz.com' domains directly.
The environment variable GLOBAL_AGENT_HTTPS_PROXY
can be set to specify a separate proxy for HTTPS requests. When this variable is not set GLOBAL_AGENT_HTTP_PROXY
is used for both HTTP and HTTPS requests.
global-agent
is using roarr
logger to log HTTP requests and response (HTTP status code and headers), e.g.
Export ROARR_LOG=true
environment variable to enable log printing to stdout.
Use roarr-cli
program to pretty-print the logs.
createGlobalProxyAgent
```js /**