【发布时间】:2020-01-03 22:06:19
【问题描述】:
问题:
检查 Heroku 日志时出现此错误:
code=H12 desc="请求超时" method=POST path="/delete" host=dry-falls-65221.herokuapp.com request_id=0d934a3c-84ea-4e7d-aa53-f437830b807e fwd="136.36 .41.157" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https。
我做了什么:
我检查了文档并安装了整个东西。检查应用程序here。但是,每次我尝试从列表中删除一个项目时,应用程序都会崩溃并出现 H12 错误。 我检查了 Mongo DB Atlas 中的数据库,该项目被删除,所以它的页面没有正确重定向。您可以看到,当您手动重新加载页面时,它会相应地呈现。我该如何解决这个问题?
使用 NodeJS 的代码部分,还有 Express、body-parser、mongoose、lodash:
app.post("/delete", function(req, res) {
const checkedItemId = req.body.checkbox;
const listName = req.body.listName;
if (listName === "Today") {
Item.findByIdAndRemove(checkedItemId, function(err) {
if (err) {
console.log(err);
} else {
console.log("Deleted!");
}
});
} else {
List.findOneAndUpdate({name:listName},{ $pull: {items: {_id: checkedItemId}}}, function (err, foundList) {
if(!err) {
res.redirect("/" + listName);
}
});
}
});
我还附上了 HTML 部分(使用了 EJS)
<% newListItems.forEach(function(item) { %>
<form class="item" action="/delete" method="post">
<div class="item">
<input name="checkbox" value="<%=item._id%>" type="checkbox" onChange="this.form.submit()">
<p><%= item.name %></p>
</div>
<input type="hidden" name="listName" value="<%= listTitle %>">
</form>
任何帮助将不胜感激。
【问题讨论】: