2

I have a node server sitting between my java monolith (backend) and browser. the node server handles the sever side rendering of react components and all.

I am using superagent-bluebird-promise to handle xhr on the node server. Now, the node server also hits the backend's apis and the backend can in some cases redirect an xhr call with a 30x to another URL.

Here i want to handle this. i dont want the node server to hit that redirect, but i want to catch that, and do the redirection based on some conditions.

Is that possible to handle? If yes, how?

If not, what would be the best way to handle backend redirects on the node server?

ghostCoder
  • 1
  • 9
  • 49
  • 72

1 Answers1

0

You can set redirects to 0, so the error will be thrown on first redirect. Something like this:

request.get(url)  
.redirects(0)
.then(res=>console.log({res}))
.catch(err=>console.log("Redirected to: " + err.originalError.response.headers.location));
Alex Blex
  • 34,704
  • 7
  • 48
  • 75