-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (44 loc) · 1.23 KB
/
app.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
const expess = require("express");
const bodyParser = require("body-parser");
const date = require(__dirname + "/date.js");
const app = expess();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(expess.static("public"));
const items = ["Buy Food", "Cook Food", "Eat Food"];
const workItem = [];
app.get('/', function(req, res){
const day = date.getDate();
res.render('list', {titleHead: "Home", listTitle: day, newListItem: items});
});
app.post('/', function(req, res){
const title = req.body.list;
const item = req.body.newItem;
if(item){
if(title === "Work"){
workItem.push(item);
res.redirect('/work');
}
else{
items.push(item);
res.redirect('/');
}
}
else{
if(title === "Work"){
res.redirect('/work');
}
else{
res.redirect('/');
}
}
});
app.get('/work', function(req, res){
res.render('list', {titleHead: "Work", listTitle: "Work", newListItem: workItem})
});
app.get('/about', function(req, res){
res.render('about',{titleHead: "About"});
});
app.listen(3000, function(){
console.log("Server started on port: 3000");
});