简体   繁体   English

使用 superagent-bluebird-promise 处理节点服务器上的服务器重定向

[英]Handling server redirect on node server using superagent-bluebird-promise

I have a node server sitting between my java monolith (backend) and browser.我的 Java 单体(后端)和浏览器之间有一个节点服务器。 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.我正在使用superagent-bluebird-promise来处理节点服务器上的 xhr。 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.现在,节点服务器还会访问后端的 api,在某些情况下,后端可以将带有 30x 的 xhr 调用重定向到另一个 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?如果没有,在节点服务器上处理后端重定向的最佳方法是什么?

You can set redirects to 0, so the error will be thrown on first redirect.您可以将redirects设置为 0,因此将在第一次重定向时抛出错误。 Something like this:像这样的东西:

request.get(url)  
.redirects(0)
.then(res=>console.log({res}))
.catch(err=>console.log("Redirected to: " + err.originalError.response.headers.location));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM