작성
·
252
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가 뜨는건가요?