seungmi

조건을 입력할 때 추천 음식이 출력되는 '/food' page수정

'http://localhost:3000/food/recommendation' page에서 조건을 입력하였을 때,
'http://localhost:3000/food' page에서 추천 음식이 출력되도록 post방식의 함수 수정
Showing 1 changed file with 10 additions and 5 deletions
...@@ -24,7 +24,7 @@ app.get(['/food', '/food/:id'], function(req, res) { ...@@ -24,7 +24,7 @@ app.get(['/food', '/food/:id'], function(req, res) {
24 } else if (id == 'recommendation') { 24 } else if (id == 'recommendation') {
25 res.render('recommendation.ejs', { 25 res.render('recommendation.ejs', {
26 title: 'Recommendation', 26 title: 'Recommendation',
27 - description: 'We recommend this...' 27 + description: 'Enter the conditions you want.'
28 }); 28 });
29 } 29 }
30 } else { 30 } else {
...@@ -36,16 +36,21 @@ app.get(['/food', '/food/:id'], function(req, res) { ...@@ -36,16 +36,21 @@ app.get(['/food', '/food/:id'], function(req, res) {
36 }) 36 })
37 37
38 app.post('/food', function(req, res) { 38 app.post('/food', function(req, res) {
39 - var price = req.body.price; 39 +
40 - var shape = req.body.shape;
41 - var kinds = req.body.kinds;
42 fs.readFile('data/food.json', 'utf8', function(err, data) { 40 fs.readFile('data/food.json', 'utf8', function(err, data) {
43 if (err) { 41 if (err) {
44 console.log((err)); 42 console.log((err));
45 res.status(500).send('Internal Server Error'); 43 res.status(500).send('Internal Server Error');
46 } else { 44 } else {
47 var users = JSON.parse(data); 45 var users = JSON.parse(data);
48 - res.json(users); 46 + var price = req.body.price;
47 + var shape = req.body.shape;
48 + var kinds = req.body.kinds;
49 + res.render('print.ejs',{
50 + title: 'Recommendation',
51 + description: 'We recommend this...',
52 + name: users[1]["name"]
53 + });
49 } 54 }
50 }) 55 })
51 }) 56 })
......