6

Im using the reverse proxy from the following link, currently Im getting some location and I want to update it(the location), How can I do that?

proxy.on('proxyRes', function (proxyRes, req, res) {

res.headers.location = 'http:/a/b/'

});

and I need to change it for example to be

res.headers.location = 'http:/c/d/' I will handle the logic how to change the URL but I want to know how to update it...

https://github.com/nodejitsu/node-http-proxy

SUNDARRAJAN K
  • 2,237
  • 2
  • 22
  • 38
07_05_GuyT
  • 2,787
  • 14
  • 43
  • 88

1 Answers1

2

in order to change the location headers try using res.location()

proxy.on('proxyRes', function (proxyRes, req, res) {

 res.location('http:/c/d/');

});

res.location just sets the response header. It does not set a response status code or close the response, so you can write a response body it you want, and you have to call res.end() on your own after.

Reference: Express Location , the source

Hope this helps.

SUNDARRAJAN K
  • 2,237
  • 2
  • 22
  • 38