sequlize 연습 중 오류

이제우·2023년 10월 22일
0
post-thumbnail

2023.10.22 오류

시퀄라이즈로 Get 요청을 받으면 게시글 목록을 보여주게 하고 있었는데

Cannot set headers after they are sent to the client

위와 같은 오류가 발생했다.

무슨 오류인지 찾아봤더니 서버가 클라이언트에 두번 이상의 응답을 보낼 때 나오는 오류라고 한다.


router.get('/', async (req, res) => {
   const post = await Post.findAll({
    attributes: ['id', 'title', 'content']
   });
  res.send(200).send(post);
})

위 코드에서 오류가 발생했는데 어디가 잘못된지 찾지 못해 30분을 고생했는데..

res."send(200)".send(post);
바보 같이 send를 두번 하고 있었다..

router.get('/', async (req, res) => {
   const post = await Post.findAll({
    attributes: ['id', 'title', 'content']
   });
  res.status(200).send(post);
})

간단하게 오류 해결 ;;

profile
게으른 사람 중에 제일 부지런하게 사는 사람이 꿈

0개의 댓글