Flare-k

Connect MongoDB and Setting dotenv

1 -import { videos } from "../db";
2 import routes from "../routes"; 1 import routes from "../routes";
3 2
4 export const home = (req, res) => { 3 export const home = (req, res) => {
...@@ -24,7 +23,9 @@ export const postUpload = (req, res) => { ...@@ -24,7 +23,9 @@ export const postUpload = (req, res) => {
24 res.redirect(routes.videoDetail(324393)); 23 res.redirect(routes.videoDetail(324393));
25 }; 24 };
26 25
27 -
28 -export const videoDetail = (req, res) => res.render("videoDetail", { pageTitle: "Video Detail" });
29 -export const editVideo = (req, res) => res.render("editVideo", { pageTitle: "Edit Video" });
30 -export const deleteVideo = (req, res) => res.render("deleteVideo", { pageTitle: "Delete Video" });
...\ No newline at end of file ...\ No newline at end of file
26 +export const videoDetail = (req, res) =>
27 + res.render("videoDetail", { pageTitle: "Video Detail" });
28 +export const editVideo = (req, res) =>
29 + res.render("editVideo", { pageTitle: "Edit Video" });
30 +export const deleteVideo = (req, res) =>
31 + res.render("deleteVideo", { pageTitle: "Delete Video" });
...\ No newline at end of file ...\ No newline at end of file
......
1 -export const videos = [{
2 - id: 324393,
3 - title: "Video awesome",
4 - description: "This is something I love",
5 - views: 24,
6 - videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
7 - creator: {
8 - id: 121212,
9 - name: "Nicolas",
10 - email: "nico@las.com",
11 - },
12 - },
13 - {
14 - id: 1212121,
15 - title: "Video super",
16 - description: "This is something I love",
17 - views: 24,
18 - videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
19 - creator: {
20 - id: 121212,
21 - name: "Nicolas",
22 - email: "nico@las.com",
23 - },
24 - },
25 - {
26 - id: 55555,
27 - title: "Video nice",
28 - description: "This is something I love",
29 - views: 24,
30 - videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
31 - creator: {
32 - id: 121212,
33 - name: "Nicolas",
34 - email: "nico@las.com",
35 - },
36 - },
37 - {
38 - id: 11111,
39 - title: "Video perfect",
40 - description: "This is something I love",
41 - views: 24,
42 - videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
43 - creator: {
44 - id: 121212,
45 - name: "Nicolas",
46 - email: "nico@las.com",
47 - },
48 - },
49 -];
...\ No newline at end of file ...\ No newline at end of file
1 +import mongoose from "mongoose";
2 +import dotenv from "dotenv";
3 +dotenv.config();
4 +
5 +mongoose.connect(process.env.MONGO_URL, {
6 + useNewUrlParser: true,
7 + useFindAndModify: false,
8 +});
9 +
10 +const db = mongoose.connection;
11 +
12 +const handleOpen = () => {
13 + console.log("✅ Connected to DB");
14 +};
15 +const handleError = (error) =>
16 + console.log(`🔴 Error on DB Connection: ${error}`);
17 +
18 +db.once("open", handleOpen); //connection을 열고 성공여부를 확인할 수 있는 function을 만들 것이다.
19 +db.on("error", handleError);
...\ No newline at end of file ...\ No newline at end of file
......
1 import app from "./app"; // app.js에서 export default app했기 때문에 불러올 수 있다. 1 import app from "./app"; // app.js에서 export default app했기 때문에 불러올 수 있다.
2 +import "./db";
3 +import dotenv from "dotenv";
4 +dotenv.config();
2 5
3 -const PORT = 80; 6 +const PORT = process.env.PORT || 80;
4 7
5 const handleListening = () => { 8 const handleListening = () => {
6 - console.log(`-> Listening on: http://localhost:${PORT}`); 9 + console.log(` Listening on: http://localhost:${PORT}`);
7 //call-back함수. 10 //call-back함수.
8 //PORT를 listen하기 시작할 때 함수를 호출해준다. 11 //PORT를 listen하기 시작할 때 함수를 호출해준다.
9 -} 12 +};
10 13
11 app.listen(PORT, handleListening); 14 app.listen(PORT, handleListening);
...\ No newline at end of file ...\ No newline at end of file
......