Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김태민
/
OpenSource_Project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
seungmi
2019-11-28 18:20:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
96dd77f16cca68e4a75d2695609b7f152fc79160
96dd77f1
1 parent
d0cc06cc
검색기능 구현
검색페이지에서 사용자가 입력한 값을 구글에서 검색한 결과 페이지로 redirect해주는 post함수 구현
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
app.js
app.js
View file @
96dd77f
...
...
@@ -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...'
,
...
...
Please
register
or
login
to post a comment