Project using node.js/Cloning Youtube
-
join - controllerProject using node.js/Cloning Youtube 2020. 8. 24. 11:49
User.js import passportLocalMongoose from "passport-local-mongoose"; UserSchema.plugin(passportLocalMongoose, { usernameField: "username" }); userController.js에서 User.register를 사용하려면 User.js에서 다음 2줄의 코드를 반드시 추가해줘야 한다. userController.js export const getJoin = (req, res) => { try { res.render('join', { pageTitle: 'Join' }); } catch (error) { console.log(error); res.redirect(routes.home); } }; expo..
-
passport.jsProject using node.js/Cloning Youtube 2020. 8. 24. 11:37
소개 passport는 인증 기능을 제공하고 내가 만든 애플리케이션에서 인증 기능을 제공하지 않더라도 카카오톡이나 Github의 계정을 이용해서 회원가입과 로그인을 할 수 있도록 도와준다. 설치 #npm install passport passport-local #npm install passport-local-mongoose passport-local-mongoose는 mongoDB에 사용자 회원 정보를 저장할 수 있도록 도와주고 passport의 기능을 더 쉽게 사용할 수 있는 API를 제공한다. 참고 자료 노마드 코더의 유튜브 클론 강의 passport 공식 사이트 passport-local-mongoose Github
-
multerProject using node.js/Cloning Youtube 2020. 8. 24. 09:56
소개 multer는 파일 등을 multipart 형식으로 업로드할 수 있게 도와주는 middleware다. multipart 형식이란 enctype="multipart/form-data"인 폼을 통해 업로드하는 형식을 말한다. middlewares.js 먼저 middlewares에 다음 코드를 추가한다. import multer from 'multer'; const multerAvatar = multer({ dest: 'uploads/avatar' }); export const uploadAvatar = multerAvatar.single('avatar'); app.js에는 다음 코드를 추가한다. postJoin은 controller 파트에서 새로 만들 join이다. join은 이제 getJoin과 po..
-
join - viewProject using node.js/Cloning Youtube 2020. 8. 24. 09:18
join - view 회원가입을 할 때 프로필 사진을 업로드할 수 있고 이름과 이메일 및 비밀번호(확인까지)를 사용자로부터 받는다. 그리고 이 값을 route.join 주소로 post방식으로 submit한다. /* join.pug */ extends layouts/main block content .form-container form(action=routes.join method="post").join-form .fileUpload label(for="avatar") Avatar input(type="file" name="avatar" id="avatar" accept="image/*") input(type="text" placeholder="Full name" required=true name="nam..
-
socialLogin.pugProject using node.js/Cloning Youtube 2020. 8. 24. 09:11
이제 기능별로 하나씩 html(form 형식)을 짜고 Controller 부분을 완성할 것이다. Back-end의 모든 기능을 마친 후에 CSS로 꾸미고 Front-end JS로 기능을 구현할 것이다. partials/socialLogin.pug .social-login button.social-login--github a(href=routes.github) span.social-login__icon i.fab.fa-github span.social-login__title Continue with Github button.social-login--kakao a(href=routes.kakao) span.social-login__icon i.fas.fa-comment span.social-login__ti..
-
Model - Comment.jsProject using node.js/Cloning Youtube 2020. 8. 23. 15:28
// Comment.js import mongoose from 'mongoose'; const commentSchema = new mongoose.Schema({ createdAt: String, text: { type: String, required: 'This is comment', }, creator: { type: mongoose.Schema.Types.ObjectId, ref: 'User', }, }); const model = mongoose.model('Comment', commentSchema); export default model; 참고 자료 노마드 코더의 유튜브 클론 강의 소스 코드 https://github.com/zpskek/wetube-v3/commit/130a2c8d857d71..
-
Model - Video.jsProject using node.js/Cloning Youtube 2020. 8. 23. 15:26
// Video.js import mongoose from 'mongoose'; const videoSchema = new mongoose.Schema({ title: String, description: String, videoUrl: String, createdAt: String, views: { type: Number, default: 0, }, comments: [ { type: mongoose.Schema.Types.ObjectId, ref: 'Comment', }, ], creator: { type: mongoose.Schema.Types.ObjectId, ref: 'User', }, }); const model = mongoose.model('Video', videoSchema); expor..
-
Model - User.jsProject using node.js/Cloning Youtube 2020. 8. 23. 15:23
Schema는 MongoDB의 데이터 구조다. mongoDB는 NoSQL 언어다. 그래서 관계형 데이터 언어가 아니다. mongoDB는 mongoose로 Schema를 작성해서 데이터 구조를 만들어 놓는다. Schema는 데이터가 아니다. model(=collection)을 만들고 그 model의 데이터 구조를 Schema로 작성한 것이다. 나는 UserSchema를 작성했다. name, email과 avatarUrl은 type을 String으로 했다. githubId와 kakaoId는 type을 Number로 comments와 videos는 객체를 담을 수 있는 배열로 선언했다. User.js 이외에 Video.js와 Comment.js를 만들고 그에 따른 Schema와 model을 만들면 UserSc..