유튜브 클론코딩 배포
- koyeb 사이트를 통해서 진행했음
- https://wetube-ogu-dmswl2030.koyeb.app/
[오류 정리]
1. aws를 연결한 후 이미지가 전부 깨져서 나올 때
2. Edit video가 적용 안될 때
[videoController.js]
export const postEdit = async (req, res) => {
const {
user: { _id },
} = req.session;
const { id } = req.params;
const { title, description, hashtags } = req.body;
// const video = await Video.exists({ _id: id }); //원래 코드
const video = await Video.findById(id); //수정한 부분
if (!video) {
return res.status(404).render("404", { pageTitle: "Video not found." });
}
if (String(video.owner) !== String(_id)) {
console.log(error);
req.flash("error", "You are not the the owner of the video.");
return res.status(403).redirect("/");
}
await Video.findByIdAndUpdate(id, {
title,
description,
hashtags: Video.formatHashtags(hashtags),
});
req.flash("success", "Changes saved.");
return res.redirect(`/videos/${id}`);
};
Video.findById(id)를 통해 해당 id의 video를 찾을 수 있다.
Video.findOne()은 () 안에 filter을 통해서 video를 찾을 수 있다.
video.exists()를 통해 해당 video가 있는지 없는지 true, false 형태로 반환해준다.
() 안에는 filter을 넣어서 원하는 검색 조건을 지정할 수 있다.
3. video validation failed
Video.js schema부분에서 description의 minLength를 20 -> 2로 수정하니까 에러가 발생했다
20으로 다시 되돌리니까 에러가 해결되었음
4. req.flash() requires sessions
logout을 하면 flash오류가 발생하고 새로고침하면 괜찮아지지만 찾다보니 해결방법이 있어서 적용했다
[userController.js]
export const logout = (req, res) => {
req.session.user = null;
req.session.loggedIn = false;
req.flash("info", "Bye Bye");
return res.redirect("/");
};
[아직 발생하는 오류]
[다른분들의 아이디어]
[후기]
예습을 미리해서 마지막 일주일이 부족하지 않을거라고 생각했는데 에러가 날때마다 멘탈이 많이 무너져서 힘들었고.. 무사히 배포한걸로 우선 만족이다
백앤드 부분의 강의를 들은지 너무 오래된 상태라 강의텀을 오래쉬면 안된다고 생각했고
유튭 클론코딩을 한번 듣고나니 그래도 전체적인 구조가 이해되고 재밌게 진행할 수 있었다!!