시퀄라이즈로 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);
})
간단하게 오류 해결 ;;