forked from cmda-minor-web/browser-technologies-2122
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
95 lines (70 loc) · 2.03 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import bodyParser from "body-parser";
import express from 'express';
import fs from 'fs';
// const { v4: uuidv4 } = ('uuid');
const app = express();
const port = process.env.PORT || 4000;
// Set ejs in als template engine
app.set("view engine", "ejs");
app.set("views", "./views");
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.get('/', (req, res) => {
// fs.readFile('index.ejs', 'utf8', function (err, data) {
// if (err) throw err;
// let info = JSON.parse(data);
res.render('index.ejs', {
// eerder_opgeslagen_data: info
})
});
app.get('/my-list', (req, res) => {
// fs.readFile('index.ejs', 'utf8', function (err, data)
// if (err) throw err;
// let info = JSON.parse(data);
res.render('./my-list', {
shirtInfo: shirtInfo
})
});
app.post('/my-list', (req, res) => {
console.log(req.body)
const shirtInfo = {
MainColor: req.body.color,
CollarColor: req.body.collar,
TextInput: req.body.customtext,
ShirtSize: req.body.sizes
};
let data = JSON.stringify(shirtInfo);
fs.writeFile('shirt.json', data , 'utf8', cb => {
console.log('werkt dit?');
})
// shirtInfo.id = uuidv4()
console.log('design data', shirtInfo)
res.render('my-list', {
shirtInfo: shirtInfo
})
});
app.get('/shopping-bag', (req, res) => {
// fs.readFile('index.ejs', 'utf8', function (err, data) {
// if (err) throw err;
// let info = JSON.parse(data);
res.render('shopping-bag'
//, {
//eerder_opgeslagen_data: info
//})
)
});
// app.get('/user/:id', (req, res) => {
// let input = req.params.id
// if(req.params.id) {
// if(req.params.id === 'robert') {
// input = 'nee doe maar niet';
// }
// }
// res.render('home', {
// persoon: input
// })
// })
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
});