pwa-kit icon indicating copy to clipboard operation
pwa-kit copied to clipboard

[FEATURE] Support routing outgoing traffic through an HTTP(S) Proxy

Open johnboxall opened this issue 3 years ago • 5 comments

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:

  1. Install the better-https-proxy-agent and http-proxy-middleware packages
  2. Define express routes for “custom proxies” as shown in the above example for SCAPI and OCAPI
  3. Update your proxy settings. My example uses MITMProxy, but it should work w/ any HTTPS proxy.
  4. Alter the PWA code to use the custom proxies
  5. Celebrate! 🥳

johnboxall avatar Jan 27 '22 00:01 johnboxall

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.

johnboxall avatar Apr 13 '22 18:04 johnboxall

~This approach is likely also blocked by #733.~ Wait – this is only useful for local development, which doesn't have this issue.

johnboxall avatar Sep 22 '22 05:09 johnboxall

This issue has been linked to a new work item: W-12145701

git2gus[bot] avatar Nov 30 '22 20:11 git2gus[bot]

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

johnboxall avatar Mar 01 '23 14:03 johnboxall

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

johnboxall avatar Mar 17 '23 16:03 johnboxall