我们使用的一个SaaS提供商有一个webook字段,但只允许输入一个url。实际上,我们需要将此webhook发送给两个分析服务,因此我需要找出一种方法来编写自定义端点,以将整个请求转发到我们需要的其他端点(当前为2个)。如何将一个POST请求转发到两个外部URL?
用node和express做这个最简单的方法是什么?如果我没有弄错,简单的重定向不适用于多个POST,对吧?
我不知道什么头,甚至要求内容将是什么样子,但它需要在身份验证的情况下被保留尽可能在头等等
这是我到目前为止,但它远不完整:
app.post('/', (req, res) => {
console.log('Request received: ', req.originalUrl)
const forwardRequests = config.forwardTo.map(url => {
return new Promise((resolve, reject) => {
superagent
.post(url)
.send(req)
.end((endpointError, endpointResponse) => {
if (endpointError) {
console.error(`Received error from forwardTo endpoint (${url}): `, endpointError)
reject(endpointError)
} else {
resolve(endpointResponse)
}
})
})
})
Promise.all(forwardRequests)
.then(() => res.sendStatus(200))
.catch(() => res.sendStatus(500))
})
我得到一个错误,因为superagent.send
仅仅是内容...我怎么能完全复制的请求,并把它关闭?