node.js - req.on('end') 没有运行 Firebase express Node.js Nylas
问题描述
我正在尝试使用 Nylas 创建 webhook,在他们的示例中,有一个中间件(代码如下)。我正在使用 Firebase 端点,我的代码是用打字稿编写的。我尝试使用 ngrok 在新项目中本地复制 Nylas 示例,中间件成功返回 200 状态。但是,当我在 Firebase 函数中使用完全相同的代码时,中间件会停止req.on('end
并超时,所以我收到console.log('2')
但不是console.log('3')
。Firebase 声称,在设置计费之前,第三方服务受到限制。这会影响中间件吗?为什么req.on('end
不开火?
req.rawBody = "";
console.log("1");
req.on("data", (chunk) => (req.rawBody += chunk));
req.on("error", (err) => res.status(500).send("Error parsing body"));
console.log("2");
req.on("end", () => {
console.log("3");
// because the stream has been consumed, other parsers like bodyParser.json
// cannot stream the request data and will time out so we must explicitly parse the body
try {
console.log("4");
req.body = JSON.parse(req.rawBody);
console.log(req.body);
next();
} catch (err) {
res.status(500).send("Error parsing body");
}
});
});
app.use(bodyParser.urlencoded({ limit: "5mb", extended: true }));
解决方案
解决方案:
通过使用这种方法解析数据得到状态 200 。
推荐阅读
- alfresco - Alfresco,在放大器中嵌入二进制文件
- c# - C# 使用函数将值添加到列表
- amazon-web-services - 如何在 ansible 中为 elb_target_group 配置慢启动持续时间?
- javascript - 如何在 FullCalendar 中调用事件的自定义属性或字段?
- symfony - Symfony 4 JWT 身份验证 - 登录前事件监听器
- javascript - 在脚本中导入类
- java - 接受来自控制台以及管道文本文件的 Java 输入
- html - 如何将图像与菜单中的文本放在同一行
- postgresql - Ecto 不会在数据库中插入 :date 字段 - 为什么?
- c# - 是/否 bot framework V4 自适应卡提示问题