-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdapp.js
79 lines (43 loc) · 1.31 KB
/
oldapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require("express");
const date = require(__dirname + "/date.js");
const app = express();
const newItems = [];
const workItems = [];
app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
///// root route /////
app.get("/", function (req, res) {
let day = date.getDate();
/// list.ejs에 app.js파일에서 생성한 변수, 리스트를 보냄 ///
res.render("list", { listTitle: day, addToDo: newItems });
});
/// root route의 form태그에서 전달된 post request를 받음 ///
app.post("/", function (req, res) {
console.log(req.body);
let newItem = req.body.toDo;
if (req.body.list == "Work") {
workItems.push(newItem);
res.redirect("/work");
} else {
newItems.push(newItem);
res.redirect("/");
}
});
///// work route /////
app.get("/work", function (req, res) {
res.render("list", { listTitle: "Work List", addToDo: workItems });
});
/// work route의 form태그에서 전달된 post request를 받음 ///
app.post("/work", function (req, res) {
let item = req.body.toDo;
workItems.push(item);
res.redirect("/work");
});
///// about route /////
app.get("/about", function(req, res) {
res.render("about")
})
app.listen(3000, function () {
console.log("server is on 3000");
});