검색기능 구현
검색페이지에서 사용자가 입력한 값을 구글에서 검색한 결과 페이지로 redirect해주는 post함수 구현
Showing
1 changed file
with
10 additions
and
3 deletions
... | @@ -12,8 +12,9 @@ app.use(bodyParser.urlencoded({ | ... | @@ -12,8 +12,9 @@ app.use(bodyParser.urlencoded({ |
12 | app.set('views', __dirname + '/views'); | 12 | app.set('views', __dirname + '/views'); |
13 | app.set('views engine', 'ejs'); | 13 | app.set('views engine', 'ejs'); |
14 | 14 | ||
15 | -app.get(['/food', '/food/:id'], function(req, res) { | ||
16 | 15 | ||
16 | +//main page | ||
17 | +app.get(['/food', '/food/:id'], function(req, res) { | ||
17 | var id = req.params.id; | 18 | var id = req.params.id; |
18 | if (id) { | 19 | if (id) { |
19 | if (id == 'search') { | 20 | if (id == 'search') { |
... | @@ -35,7 +36,14 @@ app.get(['/food', '/food/:id'], function(req, res) { | ... | @@ -35,7 +36,14 @@ app.get(['/food', '/food/:id'], function(req, res) { |
35 | } | 36 | } |
36 | }) | 37 | }) |
37 | 38 | ||
38 | -app.post('/food', function(req, res) { | 39 | +//사용자가 호출한 search page |
40 | +app.post('/food/search', function(req, res) { | ||
41 | + var title=req.body.title; | ||
42 | + res.redirect("https://www.google.com/search?q="+title+"&oq="+title+"&aqs=chrome..69i57j0l3j69i60j69i61.3149j0j9&sourceid=chrome&ie=UTF-8") | ||
43 | +}) | ||
44 | + | ||
45 | +//사용자가 호출한 recommendation page | ||
46 | +app.post('/food/recommendation', function(req, res) { | ||
39 | fs.readFile('data/food.json', 'utf8', function(err, data) { | 47 | fs.readFile('data/food.json', 'utf8', function(err, data) { |
40 | if (err) { | 48 | if (err) { |
41 | console.log((err)); | 49 | console.log((err)); |
... | @@ -56,7 +64,6 @@ app.post('/food', function(req, res) { | ... | @@ -56,7 +64,6 @@ app.post('/food', function(req, res) { |
56 | i++; | 64 | i++; |
57 | } | 65 | } |
58 | 66 | ||
59 | - console.log(rand); | ||
60 | res.render('print.ejs', { | 67 | res.render('print.ejs', { |
61 | title: 'Recommendation', | 68 | title: 'Recommendation', |
62 | description: 'We recommend this...', | 69 | description: 'We recommend this...', | ... | ... |
-
Please register or login to post a comment