沒有內存泄漏,而你不想打電話next()
如果沒有更多的中間件(res.send()
後)運行。 next()
是一個cb函數的佔位符。這就是中間件,它是一個或多個順序調用的函數,直到到達請求 - 響應週期的末尾。在本例中,當我們點擊login
端點時,我們將運行2箇中間件:validate
和changeStuff
,然後我們調用returnResponse
函數並且結束請求 - 響應循環。
get('/login',
validate,
changeStuff,
returnResponse
);
function validate(req, res, next) {
//validate logic does something then calls next()
next()
//just like calling changeStuff(req, res, next)
}
function changeStuff(req, res, next) {
//changeStuff logic changes something then calls next()
next()
//just like calling returnResponse(req, res, next)
}
function returnResponse(req, res) {
//will return something and that is the end of the req-res cycle
//there are no more functions to call, if you try to call next()
//you would get an error, because at this point next() would be
//undefined
res.send(req.body)
}
它對**中間件**這麼說,但你在問路由。你確定你正在閱讀文檔的正確部分嗎?你知道中間件是什麼嗎? – Mjh
發佈您的代碼以更好地解釋問題 –