Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강연욱
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-06-02 22:54:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
06d13dd6b8d13012c262e59bb28b904db3036f6f
06d13dd6
1 parent
85585a55
[Modified] Video DB and videoDetail View
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
7 deletions
.gitignore
app.js
controllers/videoController.js
middlewares.js
views/home.pug
views/videoDetail.pug
.gitignore
View file @
06d13dd
...
...
@@ -115,4 +115,5 @@ dist
.yarn/build-state.yml
.pnp.*
package-lock.json
\ No newline at end of file
package-lock.json
uploads
\ No newline at end of file
...
...
app.js
View file @
06d13dd
...
...
@@ -13,6 +13,7 @@ const app = express();
app
.
use
(
helmet
());
app
.
set
(
"view engine"
,
"pug"
);
app
.
use
(
"/uploads"
,
express
.
static
(
"uploads"
));
app
.
use
(
cookieParser
());
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
//json, html, text, urlencoded 할 거 없이 다 parser할 수 있도록 설정해줘야 한다.
...
...
controllers/videoController.js
View file @
06d13dd
...
...
@@ -8,7 +8,7 @@ import Video from "../models/Video";
export
const
home
=
async
(
req
,
res
)
=>
{
try
{
const
videos
=
await
Video
.
find
({});
//모든 비디오를 가져온다.
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
videos
});
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
videos
});
//render DB에 저장된 video의 내용을 보여준다
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
videos
:
[]
});
...
...
@@ -44,8 +44,20 @@ export const postUpload = async(req, res) => {
//id는 mongoDB가 랜덤하게 만들어준다.
};
export
const
videoDetail
=
(
req
,
res
)
=>
res
.
render
(
"videoDetail"
,
{
pageTitle
:
"Video Detail"
});
export
const
videoDetail
=
async
(
req
,
res
)
=>
{
//console.log(req.params); params에 id가 있다는걸 알게 됨
const
{
params
:
{
id
},
}
=
req
;
try
{
const
video
=
await
Video
.
findById
(
id
);
//console.log(video);
res
.
render
(
"videoDetail"
,
{
pageTitle
:
"Video Detail"
,
video
});
}
catch
(
error
)
{
//console.log(error);
res
.
redirect
(
routes
.
home
);
}
};
export
const
editVideo
=
(
req
,
res
)
=>
res
.
render
(
"editVideo"
,
{
pageTitle
:
"Edit Video"
});
export
const
deleteVideo
=
(
req
,
res
)
=>
...
...
middlewares.js
View file @
06d13dd
import
multer
from
"multer"
;
import
routes
from
"./routes"
;
const
multerVideo
=
multer
({
dest
:
"videos/"
});
const
multerVideo
=
multer
({
dest
:
"
uploads/
videos/"
});
export
const
localsMiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
locals
.
siteName
=
"my Youtube"
;
...
...
views/home.pug
View file @
06d13dd
...
...
@@ -8,5 +8,5 @@ block content
id: item.id,
title : item.title,
views: item.views,
videoFile:item.
videoFile
videoFile:item.
fileUrl
})
\ No newline at end of file
...
...
views/videoDetail.pug
View file @
06d13dd
extends layouts/main
block content
p Hello This is videoDetail
\ No newline at end of file
.video__player
video(src=`/${video.fileUrl}`)
.video__info
a(href=routes.editVideo) Edit video
h5.video__title=video.title
span.video__views=video.views
p.video__description=video.desription
\ No newline at end of file
...
...
Please
register
or
login
to post a comment