ませんメモリリーク、および(res.send()
後)に実行するこれ以上のミドルウェアが存在しない場合はnext()
をコールする必要はありません。 next()
は、cb関数のプレースホルダです。ミドルウェアとは、要求/応答サイクルの終わりに達するまで、順次呼び出される1つ以上の関数です。この例では、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
問題をより詳しく説明するコードを投稿する –