Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-05-26 21:57:49 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
127cd672e3fe79ac87867ef33c13ac57830f30c1
127cd672
1 parent
6a0f9b08
[Connect] Controller and DB
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletions
controllers/videoController.js
controllers/videoController.js
View file @
127cd67
import
routes
from
"../routes"
;
import
Video
from
"../models/Video"
;
export
const
home
=
(
req
,
res
)
=>
{
//db를 import 해주고 home에 async를 달아준다. async는 기다려주는 역할을 한다.
//javascript가 db를 다 못보고 그냥 지나갈 수도 있기 때문이다.
//javascript는 기본적으로 기다려주지 않는다.
//async: "JS야 이 function의 ~~부분은 꼭 기다려!" await이 있는 부분까지 기다린다.
export
const
home
=
async
(
req
,
res
)
=>
{
try
{
const
videos
=
await
Video
.
find
({});
//모든 비디오를 가져온다.
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
videos
});
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
videos
:
[]
});
}
};
export
const
search
=
(
req
,
res
)
=>
{
...
...
Please
register
or
login
to post a comment