seungmi

검색기능 구현

검색페이지에서 사용자가 입력한 값을 구글에서 검색한 결과 페이지로 redirect해주는 post함수 구현
Showing 1 changed file with 10 additions and 3 deletions
......@@ -12,8 +12,9 @@ app.use(bodyParser.urlencoded({
app.set('views', __dirname + '/views');
app.set('views engine', 'ejs');
app.get(['/food', '/food/:id'], function(req, res) {
//main page
app.get(['/food', '/food/:id'], function(req, res) {
var id = req.params.id;
if (id) {
if (id == 'search') {
......@@ -35,7 +36,14 @@ app.get(['/food', '/food/:id'], function(req, res) {
}
})
app.post('/food', function(req, res) {
//사용자가 호출한 search page
app.post('/food/search', function(req, res) {
var title=req.body.title;
res.redirect("https://www.google.com/search?q="+title+"&oq="+title+"&aqs=chrome..69i57j0l3j69i60j69i61.3149j0j9&sourceid=chrome&ie=UTF-8")
})
//사용자가 호출한 recommendation page
app.post('/food/recommendation', function(req, res) {
fs.readFile('data/food.json', 'utf8', function(err, data) {
if (err) {
console.log((err));
......@@ -56,7 +64,6 @@ app.post('/food', function(req, res) {
i++;
}
console.log(rand);
res.render('print.ejs', {
title: 'Recommendation',
description: 'We recommend this...',
......