-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
next()후 다음에 실행할 미들웨어가 없으면
22.07.17 15:03 작성 조회수 153
0
app.get('/',(req,res,next)=>{
console.log("/ 라우터");
res.sendFile(path.join(__dirname,'/index.html'));
next();
},(req,res,next)=>{
console.log("/ 라우터의 두번째 미들웨어");
// next();
});
app.get('/about',(req,res)=>{
console.log("about 라우터");
});
-> 정상
app.get('/',(req,res,next)=>{
console.log("/ 라우터");
res.sendFile(path.join(__dirname,'/index.html'));
next();
},(req,res,next)=>{
console.log("/ 라우터의 두번째 미들웨어");
next();
});
app.get('/about',(req,res)=>{
console.log("about 라우터");
});
-> 404 Not Found
app.get('/',(req,res,next)=>{
console.log("/ 라우터");
res.sendFile(path.join(__dirname,'/index.html'));
next();
},(req,res,next)=>{
console.log("/ 라우터의 두번째 미들웨어");
next();
});
app.get('*',(req,res)=>{
console.log("* 라우터");
});
app.get('/about',(req,res)=>{
console.log("about 라우터");
});
-> 정상
세가지 코드를 비교해봤는데,
localhost:3000/ 접속시 두번째 코드에서 404 Not Found가 뜨는 이유는 next()로 다음 미들웨어를 실행했는데, 실행할 미들웨어가 없어서 404가 뜨는건가요?
답변을 작성해보세요.
1
답변 1