// 미들웨어
// 공통되는 코드
app.use(
(req, res, next) => {
console.log('1 모든 요청에 실행하고 싶어요');
next();
},
(req, res, next) => {
console.log('2 모든 요청에 실행하고 싶어요');
next();
},
(req, res, next) => {
console.log('3 모든 요청에 실행하고 싶어요');
next();
},
(req, res, next) => {
console.log('4 모든 요청에 실행하고 싶어요');
next();
}
);
// express server start!!
// 1 모든 요청에 실행하고 싶어요
// 2 모든 요청에 실행하고 싶어요
// 3 모든 요청에 실행하고 싶어요
// 4 모든 요청에 실행하고 싶어요
미들웨어 에러처리
app.use(
(req, res, next) => {
console.log('1 모든 요청에 실행하고 싶어요');
next();
},
(req, res, next) => {
throw new Error('에러가 났어요.');
}
);