김태민

이미지 출력 추가

...@@ -4,6 +4,7 @@ var bodyParser = require('body-parser'); ...@@ -4,6 +4,7 @@ var bodyParser = require('body-parser');
4 var fs = require("fs"); 4 var fs = require("fs");
5 5
6 app.use(express.static('public')); 6 app.use(express.static('public'));
7 +app.use('/images', express.static(__dirname + '/images'));
7 app.use(bodyParser.json()); 8 app.use(bodyParser.json());
8 app.use(bodyParser.text()); 9 app.use(bodyParser.text());
9 app.use(bodyParser.urlencoded({ 10 app.use(bodyParser.urlencoded({
...@@ -106,11 +107,15 @@ app.post('/food/recommendation', function(req, res) { ...@@ -106,11 +107,15 @@ app.post('/food/recommendation', function(req, res) {
106 console.log('food 갯수: '+length); 107 console.log('food 갯수: '+length);
107 var rand = Math.floor(Math.random() * length); //(Math.random() * (max - min)) + min 108 var rand = Math.floor(Math.random() * length); //(Math.random() * (max - min)) + min
108 var food_value = food[rand]; 109 var food_value = food[rand];
110 + var food_picture = '/images/' + food_value + ".png";
111 +
112 +
109 console.log('랜덤 food 번호: '+rand); 113 console.log('랜덤 food 번호: '+rand);
110 res.render('print.ejs', { 114 res.render('print.ejs', {
111 title: 'Recommendation', 115 title: 'Recommendation',
112 description: 'We recommend this...', 116 description: 'We recommend this...',
113 - randvalue: food_value 117 + randvalue: food_value,
118 + picture : food_picture
114 }); //rander closed 119 }); //rander closed
115 }); //add closed 120 }); //add closed
116 } 121 }
......
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 +
2 <html lang="en" dir="ltr"> 3 <html lang="en" dir="ltr">
3 4
4 <head> 5 <head>
...@@ -22,8 +23,8 @@ ...@@ -22,8 +23,8 @@
22 </h2> 23 </h2>
23 <p><%= description %></p> 24 <p><%= description %></p>
24 <p><%= randvalue%></p> 25 <p><%= randvalue%></p>
26 + <img src = <%= picture%>>
25 </article> 27 </article>
26 </div class="grid"> 28 </div class="grid">
27 -</body>
28 29
29 </html> 30 </html>
......