node-http-proxyhttp-proxy-middleware

How to use http-proxy-middleware / node-http-proxy as a reverse proxy?


I'm investigating the use of http-proxy-middleware / node-http-proxy as a reverse proxy. Does anyone know if this is really possible?

I've already setup http-proxy-middleware so that I can proxy a request through it (the results are displayed in an iframe), and I'm also able to modify the request headers and html results. Specifically, I'm setting the host/origin headers and rewriting the result to change embedded links so that they go through the proxy as well.

But, some links are generated by js, and rewriting javascript responses seems to be very difficult to do correctly.

Is there a way to do this without rewriting links? I.e., is there any method to configure the iframe to automatically send all requests through the proxy?

Or maybe this is not really possible, and I'd need to use a full proxy like Squid?

Thanks!


Solution

  • This does seem to be possible, to a limited extent. http-proxy-middleware can be configured to edit response headers and to also rewrite the response body, so that links can be rewritten to use the proxy URL. XmlHttpRequest and fetch() requests can also be intercepted to rewrite the requests to use the proxy URL.