【问题标题】:Handling server redirect on node server using superagent-bluebird-promise使用 superagent-bluebird-promise 在节点服务器上处理服务器重定向
【发布时间】:2018-04-12 09:27:32
【问题描述】:

我的 Java 单体(后端)和浏览器之间有一个节点服务器。节点服务器处理 React 组件和所有的服务器端渲染。

我正在使用superagent-bluebird-promise 在节点服务器上处理 xhr。现在,节点服务器还会访问后端的 api,并且在某些情况下,后端可以将具有 30x 的 xhr 调用重定向到另一个 URL。

我想在这里处理这个。我不希望节点服务器命中该重定向,但我想抓住它,并根据某些条件进行重定向。

这可以处理吗?如果是,怎么做?

如果不是,在节点服务器上处理后端重定向的最佳方法是什么?

【问题讨论】:

  • 您的问题是“如何在 HTTP 重定向之后自动停止 superagent-bluebird-promise?”
  • @Quentin 是的!就是这样

标签: javascript node.js redirect bluebird superagent


【解决方案1】:

您可以将redirects 设置为0,这样在第一次重定向时就会抛出错误。像这样的:

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

【讨论】:

    猜你喜欢
    • 2017-11-15
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 2021-05-28
    • 2020-11-11
    • 2017-05-31
    • 2011-11-05
    • 1970-01-01
    相关资源
    最近更新 更多