node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

hostRewrite/autoRewrite clarity

Open avaer opened this issue 8 years ago • 3 comments

From the Readme:

hostRewrite: rewrites the location hostname on (201/301/302/307/308) redirects.
autoRewrite: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.

The following is not clear:

  • How does hostRewrite rewrite? To the target? To the response header?
  • What is the precedence of these options? Seems that they are not logically compatible.
  • What is the hostRewrite default?

avaer avatar Jan 08 '18 20:01 avaer

please answer... I want to know that, too...

savigny030 avatar Nov 07 '19 14:11 savigny030

https://github.com/http-party/node-http-proxy/blob/a3fe02d651d05d02d0ced377c22ae8345a2435a4/lib/http-proxy/passes/web-outgoing.js#L50-L73

hostRewrite expects a string, default is null autoRewrite is a boolean and uses the Host header from the request, default is false

agriffis avatar Aug 06 '20 22:08 agriffis

given that my frontend has hostname as www.frontend.com and the target or backend has hostname as my.internal.io, and my internal web server has generated some anchor links in html with href pointing to absolute internal URL, e.g Foo page href="https://my.internal.io/foo.html", I'm wondering if the http-proxy could automatically rewrite the above mentioned anchor as following via hostRewrite: Foo page href="https://www.frontend.com/foo.html" otherwise, the Foo Page link won't be accessible from a browser since it has an unreachable internal URL

idavollen avatar Oct 22 '22 19:10 idavollen