没有内存泄漏,而你不想打电话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
发布您的代码以更好地解释问题 –