我是 Express 和 Node 的新手,当使用 Advanced REST Client 在我的应用程序中测试受保护的 REST 端点时,数据会按预期从端点返回到客户端,但是控制台会记录
"Error: Can't set headers after they are sent"
停止服务器。在 SO 上搜索,这似乎在发送多个响应时发生,但我在我的代码中没有看到:
router.get('/books', userAuthenticated, function (req, res, next) {
Book.find({}, function(err, docs){
if(err) {
res.send(err)
} else {
res.send(docs);
// next();
// return;
}
})
});
向/从客户端发送请求/响应时是否会出现此错误,或者我在处理服务器上的错误时遗漏了什么?