express middleware
기본
const middleware = (req, res, next) => {
console.log('middleware')
next()
})
router.use('path', middleware, (req, res, next) => {
console.log('route')
})
결과
middleware
route
다중 미들웨어
const middleware1 = (req, res, next) => {
console.log('middleware1')
next()
})
const middleware2 = (req, res, next) => {
console.log('middleware2')
next()
})
// 순서대로 미들웨어 수행
router.use('path', middleware1, middleware2, (req, res, next) => {
console.log('route')
})
결과
middleware1
middleware2
route
댓글남기기