[FEATURE] Support routing outgoing traffic through an HTTP(S) Proxy
In high control IT environments, outgoing traffic may required to route through a central corporate proxy:
Browser -> DevServer -> Corp Proxy -> Internet.
Currently using PWA Kit development server in such an environment is possible, but not straight forward:
https://github.com/SalesforceCommerceCloud/pwa-kit/compare/example-using-proxy
Ideally, we'd have a setting similar to npm's https-proxy setting that would route all requests through the proxy.
For folks looking for a workaround in the interim, in broad stokes you must:
- Install the better-https-proxy-agent and http-proxy-middleware packages
- Define express routes for “custom proxies” as shown in the above example for SCAPI and OCAPI
- Update your proxy settings. My example uses MITMProxy, but it should work w/ any HTTPS proxy.
- Alter the PWA code to use the custom proxies
- Celebrate! 🥳
Adding onto this, it might be valuable if the devserver had native support for routing proxy requests through a proxy (like MITMProxy). This can be helpful for debugging errors with API requests that happen in the context of the server.
~This approach is likely also blocked by #733.~ Wait – this is only useful for local development, which doesn't have this issue.
This issue has been linked to a new work item: W-12145701
Besides the use case of routing traffic through a proxy to adhere to corporate network policies, it can also be useful to route traffic through a proxy to help with debugging:
https://user-images.githubusercontent.com/28967/222162522-c94e1d01-bdb8-48a6-9837-cf2e468be1e2.mp4
It would also be useful if there was a feature switch you could enable to see what network requests your app is making.
Something similar to NODE_DEBUG=http
Could potentially be implemented as part of our default agent and toggled using upcoming support for environment variables:
https://github.com/SalesforceCommerceCloud/pwa-kit/blob/918f4e50ec7a74a0da088f8901d750a62faf1c11/packages/pwa-kit-runtime/src/utils/ssr-server/outgoing-request-hook.js