Flare-k

Add View in MVC Pattern

...@@ -3,20 +3,22 @@ import morgan from "morgan"; ...@@ -3,20 +3,22 @@ import morgan from "morgan";
3 import helmet from "helmet"; 3 import helmet from "helmet";
4 import cookieParser from "cookie-parser"; 4 import cookieParser from "cookie-parser";
5 import bodyParser from "body-parser"; 5 import bodyParser from "body-parser";
6 +import { localsMiddleware } from "./middlewares";
7 +import routes from "./routes";
6 import userRouter from "./routers/userRouter"; 8 import userRouter from "./routers/userRouter";
7 import videoRouter from "./routers/videoRouter"; 9 import videoRouter from "./routers/videoRouter";
8 import globalRouter from "./routers/globalRouter"; 10 import globalRouter from "./routers/globalRouter";
9 -import routes from "./routes";
10 -const app = express();
11 11
12 +const app = express();
12 13
14 +app.use(helmet());
15 +app.set("view engine", "pug");
13 app.use(cookieParser()); 16 app.use(cookieParser());
14 app.use(bodyParser.json()); 17 app.use(bodyParser.json());
15 app.use(bodyParser.urlencoded({ extended: true })); //json, html, text, urlencoded 할 거 없이 다 parser할 수 있도록 설정해줘야 한다. 18 app.use(bodyParser.urlencoded({ extended: true })); //json, html, text, urlencoded 할 거 없이 다 parser할 수 있도록 설정해줘야 한다.
16 -app.use(helmet());
17 app.use(morgan("dev")); 19 app.use(morgan("dev"));
18 20
19 - 21 +app.use(localsMiddleware);
20 app.use(routes.home, globalRouter); 22 app.use(routes.home, globalRouter);
21 app.use(routes.users, userRouter); 23 app.use(routes.users, userRouter);
22 app.use(routes.videos, videoRouter); 24 app.use(routes.videos, videoRouter);
......
1 -export const join = (req, res) => res.send("join");
2 -export const login = (req, res) => res.send("login");
3 -export const logout = (req, res) => res.send("logout");
4 -export const users = (req, res) => res.send("users");
5 -export const userDetail = (req, res) => res.send("user Detail");
6 -export const editProfile = (req, res) => res.send("Edit Profile");
7 -export const changePassword = (req, res) => res.send("Change Password");
...\ No newline at end of file ...\ No newline at end of file
1 +export const join = (req, res) => res.render("join");
2 +export const login = (req, res) => res.render("login");
3 +export const logout = (req, res) => res.render("logout");
4 +export const users = (req, res) => res.render("users");
5 +export const userDetail = (req, res) => res.render("userDetail");
6 +export const editProfile = (req, res) => res.render("editProfile");
7 +export const changePassword = (req, res) => res.render("changePassword");
...\ No newline at end of file ...\ No newline at end of file
......
1 -export const home = (req, res) => res.send("home");
2 -export const search = (req, res) => res.send("search");
3 -export const videos = (req, res) => res.send("videos");
4 -export const upload = (req, res) => res.send("upload");
5 -export const videoDetail = (req, res) => res.send("videoDetail");
6 -export const editVideo = (req, res) => res.send("editVideo");
7 -export const deleteVideo = (req, res) => res.send("deleteVideo");
...\ No newline at end of file ...\ No newline at end of file
1 +export const home = (req, res) => res.render("home");
2 +export const search = (req, res) => res.render("search");
3 +export const videos = (req, res) => res.render("videos");
4 +export const upload = (req, res) => res.render("upload");
5 +export const videoDetail = (req, res) => res.render("videoDetail");
6 +export const editVideo = (req, res) => res.render("editVideo");
7 +export const deleteVideo = (req, res) => res.render("deleteVideo");
...\ No newline at end of file ...\ No newline at end of file
......
1 +import routes from "./routes";
2 +
3 +export const localsMiddleware = (req, res, next) => {
4 + res.locals.siteName = 'my Youtube';
5 + res.locals.routes = routes;
6 + next();
7 +};
...\ No newline at end of file ...\ No newline at end of file
...@@ -20,9 +20,10 @@ ...@@ -20,9 +20,10 @@
20 "cookie-parser": "^1.4.5", 20 "cookie-parser": "^1.4.5",
21 "express": "^4.17.1", 21 "express": "^4.17.1",
22 "helmet": "^3.22.0", 22 "helmet": "^3.22.0",
23 - "morgan": "^1.10.0" 23 + "morgan": "^1.10.0",
24 + "pug": "^2.0.4"
24 }, 25 },
25 "devDependencies": { 26 "devDependencies": {
26 "nodemon": "^2.0.4" 27 "nodemon": "^2.0.4"
27 } 28 }
28 -}
...\ No newline at end of file ...\ No newline at end of file
29 +}
......
...@@ -4,7 +4,6 @@ import { users, userDetail, editProfile, changePassword } from "../controllers/u ...@@ -4,7 +4,6 @@ import { users, userDetail, editProfile, changePassword } from "../controllers/u
4 4
5 const userRouter = express.Router(); 5 const userRouter = express.Router();
6 6
7 -
8 userRouter.get(routes.users, users); 7 userRouter.get(routes.users, users);
9 userRouter.get(routes.userDetail, userDetail); 8 userRouter.get(routes.userDetail, userDetail);
10 userRouter.get(routes.editProfile, editProfile); 9 userRouter.get(routes.editProfile, editProfile);
......
...@@ -11,5 +11,4 @@ videoRouter.get(routes.videoDetail, videoDetail); ...@@ -11,5 +11,4 @@ videoRouter.get(routes.videoDetail, videoDetail);
11 videoRouter.get(routes.editVideo, editVideo); 11 videoRouter.get(routes.editVideo, editVideo);
12 videoRouter.get(routes.deleteVideo, deleteVideo); 12 videoRouter.get(routes.deleteVideo, deleteVideo);
13 13
14 -
15 export default videoRouter; 14 export default videoRouter;
...\ No newline at end of file ...\ No newline at end of file
......
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is change Password
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is delete Video
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is edit Profile
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is edit Video
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Pug
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Join
...\ No newline at end of file ...\ No newline at end of file
1 +//공통되는 코드가 필요한 경우div
2 +
3 +doctype html
4 +html
5 + head
6 + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
7 + title | #{siteName}
8 + body
9 + include ../partials/header
10 + main
11 + block content
12 + include ../partials/footer
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Login
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Logout
...\ No newline at end of file ...\ No newline at end of file
1 +footer.footer
2 + .footer_icon
3 + i.fab.fa-youtube
4 + span.footer__text #{siteName} #{new Date().getFullYear()} &copy;
1 +header.header
2 + .header__column
3 + a(href=routes.home)
4 + i.fab.fa-youtube
5 + .header__column
6 + ul
7 + li
8 + a(href=routes.join) Join
9 + li
10 + a(href=routes.login) Log In
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Search
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Upload
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is userDetail
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is Users
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is videoDetail
...\ No newline at end of file ...\ No newline at end of file
1 +extends layouts/main
2 +
3 +block content
4 + p Hello This is videos
...\ No newline at end of file ...\ No newline at end of file