我对这些路线有疑问
# Routes
#
router.get "/calendars", (req, res, next) ->
Calendar.find (err, calendar) ->
return next(err) if err
res.json calendar
return
return
router.post "/calendars", (req, res, next) ->
calendar = new Calendar(req.body)
calendar.save (err, post) ->
return next(err) if err
res.json post
return
return
当我向任一API端点发送请求时,服务器挂起并最终导致请求超时错误
为什么会这样?
答案 0 :(得分:0)
编辑:立即尝试。我觉得这里没有任何问题。运行POST后,在控制台中查找“checkpoint”。如果它仍然不起作用,请告诉我。我想知道你是如何调用API的。 确保在调用之前定义了日历模型。
mongoose = require("mongoose")
Calendar = mongoose.model("Calendar")
ObjectId = require("mongoose").Types.ObjectId
router.get "/calendars", (req, res) ->
Calendar.find (err, calendar) ->
res.send err if err
res.json calendar
return
return
router.post "/calendars", (req, res) ->
console.log "checkpoint: " + JSON.stringify(req.body)
calendar = new Calendar(
day: req.body.day
month: req.body.month
year: req.body.year
)
calendar.save (err, post) ->
res.send err if err
res.json post
return
return