【发布时间】:2020-02-21 04:29:36
【问题描述】:
当我发出 GET 请求时,我 console.log(response) 得到一个 404
Http failure response for http://localhost:3000/api/watchings/?watchItemUniqueKey=5dab6083b68bd049c0b8f9ce%7C5daf5e0c8d261e5364acd8b6: 404 Not Found", err
所以我知道该值是作为参数传递的,但我的 app.js 文件没有看到它。此外,app.get 开头的 console.log("output: " + req.params.test); 没有输出,因此来自 watch-list.service.ts 的 GET 请求没有命中 app.js 文件。
任何帮助表示赞赏。我一个月前才开始学习 nodejs,所以还在研究它是如何工作的。
watch-list.service.ts
getWatchList(watchingId) {
watchingId = watchingId.trim();
let params1 = new HttpParams().set('watchItemUniqueKey', watchingId);
return this.http.get<{}>(
'http://localhost:3000/api/watchings/', {params: params1}
).
subscribe((response) => {
console.log(response);
});
}
app.js
app.get("/api/watchings/:test", (req, res, next) => {
console.log("output: " + req.params.test);
Watching.find({"value": req.params.test})
.then(documents =>{
res.status(200).json({
message: "Posts fetched Successfully",
watchItems: documents,
});
});
});
【问题讨论】:
标签: node.js angular express mongoose