Repository navigation
Conversation
Added support for network proxy agent in http-proxy-middleware, configured via package.json or 'PROXY_AGENT' env var
- Documented use of the agent property in the proxy config of package.json - Documented use of the PROXY_AGENT env var
Removed superfluous `e.g.` from line 1050-1051 (Accidental artifact from previous commit)
Fixed header capitilaztion on line [1117](https://github.com/thtliife/create-react-app/tree/proxy-agent-for-http-proxy-middleware/packages/react-scripts/template#configuring-the-proxy-behind-a-network-proxy) for continuity with existing formatting
Re-added accidentally removed whitespace at line 1049
|
A lot of tooling and programming languages use the following environment variables to configure a network proxy: Think it would be nice to keep this pattern. Not sure redefining the "agent" option is a good idea. |
|
Hi @thtliife do you may know a way of using this without having to eject? There is an agent property already available but I couldn't find a way to pass down an properly configured proxy-agent object to make use of it. |
|
Please post your suggestion in #3366 and try to reach consensus with other proxy users. This option is getting really complicated and I'd like to ensure people who use it align in what they want. Thanks! |
The Problem
As specified in issue #2998
When using the http-proxy-middleware package configured via package.json to proxy requests to an external address, no method exists to configure an agent to pass traffic through a network proxy.
The Solution
I have made changes to WebpackDevServerUtils to enable using the https-proxy-agent package to add network proxy support to the http-proxy-middleware package, via either an
agentproperty in package.json, or aPROXY_AGENTenvironment variable.Usage info has been added to the react-scripts README.md as below:
If you are behind a network proxy (common in corporate environments), and require requests to the url specified in the
targetproperty of theproxyobject to be forwarded through your network proxy, you may specify anagentproperty in yourpackage.jsonunder theproxyobject.The
agentproperty must be a string value representing either the environment variable containing your network proxy configuration (case sensitive), or the proxy configuration itself, in the format:<protocol>://[<username>:<password>@]<proxy_address>:<port>eg:
http://myproxy.com:8080or:
http://my_name:my_password@myproxy.com:8080You may also set the network proxy for all specified proxies via an environment variable named
PROXY_AGENTeither in your system environment variables or your.envor.env.developmentfiles.If the
PROXY_AGENTenvironment variable exists, it will be used for all proxies which do not explicitly set anagentproperty manually. If you need to exclude a proxy from using thePROXY_AGENTvalue, simply set theagentproperty to "none".A more complete example of using the proxy agent is: