없음 메모리 누수가, 당신은 (res.send()
후) 실행 더 이상 미들웨어가없는 경우 next()
를 호출하고 싶지 않아요. next()
은 cb 함수의 자리 표시 자입니다. 이것이 미들웨어이며, 요청 - 응답 사이클의 끝까지 도달 할 때까지 순차적으로 호출되는 하나 이상의 함수입니다.이 예에서 login
끝 점이되면 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
문제를 더 잘 설명하는 코드 게시 –