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-25 23:33:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9dc5696aaa4746a0cfdeb61338b4167ba32de311
9dc5696a
1 parent
4d9b6f09
Connect MongoDB and Setting dotenv
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
57 deletions
controllers/videoController.js
db.js
init.js
controllers/videoController.js
View file @
9dc5696
import
{
videos
}
from
"../db"
;
import
routes
from
"../routes"
;
export
const
home
=
(
req
,
res
)
=>
{
...
...
@@ -24,7 +23,9 @@ export const postUpload = (req, res) => {
res
.
redirect
(
routes
.
videoDetail
(
324393
));
};
export
const
videoDetail
=
(
req
,
res
)
=>
res
.
render
(
"videoDetail"
,
{
pageTitle
:
"Video Detail"
});
export
const
editVideo
=
(
req
,
res
)
=>
res
.
render
(
"editVideo"
,
{
pageTitle
:
"Edit Video"
});
export
const
deleteVideo
=
(
req
,
res
)
=>
res
.
render
(
"deleteVideo"
,
{
pageTitle
:
"Delete Video"
});
\ No newline at end of file
export
const
videoDetail
=
(
req
,
res
)
=>
res
.
render
(
"videoDetail"
,
{
pageTitle
:
"Video Detail"
});
export
const
editVideo
=
(
req
,
res
)
=>
res
.
render
(
"editVideo"
,
{
pageTitle
:
"Edit Video"
});
export
const
deleteVideo
=
(
req
,
res
)
=>
res
.
render
(
"deleteVideo"
,
{
pageTitle
:
"Delete Video"
});
\ No newline at end of file
...
...
db.js
View file @
9dc5696
export
const
videos
=
[{
id
:
324393
,
title
:
"Video awesome"
,
description
:
"This is something I love"
,
views
:
24
,
videoFile
:
"https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
,
creator
:
{
id
:
121212
,
name
:
"Nicolas"
,
email
:
"nico@las.com"
,
},
},
{
id
:
1212121
,
title
:
"Video super"
,
description
:
"This is something I love"
,
views
:
24
,
videoFile
:
"https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
,
creator
:
{
id
:
121212
,
name
:
"Nicolas"
,
email
:
"nico@las.com"
,
},
},
{
id
:
55555
,
title
:
"Video nice"
,
description
:
"This is something I love"
,
views
:
24
,
videoFile
:
"https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
,
creator
:
{
id
:
121212
,
name
:
"Nicolas"
,
email
:
"nico@las.com"
,
},
},
{
id
:
11111
,
title
:
"Video perfect"
,
description
:
"This is something I love"
,
views
:
24
,
videoFile
:
"https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
,
creator
:
{
id
:
121212
,
name
:
"Nicolas"
,
email
:
"nico@las.com"
,
},
},
];
\ No newline at end of file
import
mongoose
from
"mongoose"
;
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
mongoose
.
connect
(
process
.
env
.
MONGO_URL
,
{
useNewUrlParser
:
true
,
useFindAndModify
:
false
,
});
const
db
=
mongoose
.
connection
;
const
handleOpen
=
()
=>
{
console
.
log
(
"✅ Connected to DB"
);
};
const
handleError
=
(
error
)
=>
console
.
log
(
`🔴 Error on DB Connection:
${
error
}
`
);
db
.
once
(
"open"
,
handleOpen
);
//connection을 열고 성공여부를 확인할 수 있는 function을 만들 것이다.
db
.
on
(
"error"
,
handleError
);
\ No newline at end of file
...
...
init.js
View file @
9dc5696
import
app
from
"./app"
;
// app.js에서 export default app했기 때문에 불러올 수 있다.
import
"./db"
;
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
const
PORT
=
80
;
const
PORT
=
process
.
env
.
PORT
||
80
;
const
handleListening
=
()
=>
{
console
.
log
(
`
->
Listening on: http://localhost:
${
PORT
}
`
);
console
.
log
(
`
✅
Listening on: http://localhost:
${
PORT
}
`
);
//call-back함수.
//PORT를 listen하기 시작할 때 함수를 호출해준다.
}
}
;
app
.
listen
(
PORT
,
handleListening
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment