我目前正在使用此 Contentful-webhook-server 在内容未发布时监听 Webhook。
server.listen(30000, function(){
console.log('Contentful webhook server running on port ' + 30000)
});
server.on('ContentManagement.Entry.publish', function(req){
console.log('An entry was published!', req);
});
server.on('ContentManagement.Entry.unpublish', function(req){
console.log('An entry was unpublished!');
console.log('Deleted SOLR ID: ', req);
});
我正在尝试解析我得到的响应,但我似乎找不到一种方法来解析他们在响应中使用的自定义 JSON。我是否应该使用 Express 创建自己的服务器,或者我是否缺少在此示例代码中获取响应正文的方法。
最佳答案
contentful-webhook-server
库使用普通 Node http
模块作为服务器。因此,req
对象是一个可读流,您需要对其进行缓冲和解析才能获取正文。
看看https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/#request-body举个例子。
关于json - 解析内容丰富的 Webhook(自定义 JSON 类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37838283/