1번 과제 없는 게시물 에러처리하는데
app.get('/detail/:id', function(req, res){
db.collection('post').findOne({_id : parseInt(req.params.id)}, function(err, result){
console.log(result);
res.render('detail.ejs', {data : result});
if(err) {return res.status(404).send('요청 페이지 없음')};
});
});
했는데 아무것도 안되네요. 뭔가 잘못된거 같긴한데...! 알려주세요
그리고 2번 과제
# server.js
// detail page로 이동하는 라우터
app.get('/detail/:id', function(req, res){
false.readFile('list.ejs', function(err, data){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
})
})
#list.ejs
<a href="localhost:8080/detail/:id"><h4> 할일 제목 : <%= posts[i].title %> </h4></a>
<a href="localhost:8080/detail/:id"></a><p> 할일 마감날짜 : <%= posts[i].date %> </p></a>
이렇게 했더니 제목에 파란 링크만 뜨고 페이지 이동이 안되네요. 알려주실 수 있으신가요!