Toggle navigation
Toggle navigation
This project
Loading...
Sign in
유승근
/
Computer-part-Recommand
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
1
Network
Create a new issue
Commits
Issue Boards
Authored by
Yuseunggeun
2020-06-24 19:15:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
472ac5100d66e44641cbbf1e2ffb39858f2dbd88
472ac510
1 parent
4f7738d8
add api
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
routes/main.js
routes/main.js
0 → 100644
View file @
472ac51
var
express
=
require
(
'express'
);
var
app
=
express
();
var
client_id
=
'HH0lbvfI3QtlyR7e9tkw'
;
var
client_secret
=
'mvPTEsNs7L'
;
app
.
get
(
'/search/blog'
,
function
(
req
,
res
)
{
var
api_url
=
'https://openapi.naver.com/v1/search/shop?query='
+
encodeURI
(
req
.
query
.
query
);
// json 결과
// var api_url = 'https://openapi.naver.com/v1/search/shop.xml?query=' + encodeURI(req.query.query); // xml 결과
var
request
=
require
(
'request'
);
var
options
=
{
url
:
api_url
,
headers
:
{
'X-Naver-Client-Id'
:
client_id
,
'X-Naver-Client-Secret'
:
client_secret
}
};
request
.
get
(
options
,
function
(
error
,
response
,
body
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
res
.
writeHead
(
200
,
{
'Content-Type'
:
'text/json;charset=utf-8'
});
res
.
end
(
body
);
}
else
{
res
.
status
(
response
.
statusCode
).
end
();
console
.
log
(
'error = '
+
response
.
statusCode
);
}
});
});
app
.
listen
(
3000
,
function
()
{
console
.
log
(
'http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!'
);
});
\ No newline at end of file
Please
register
or
login
to post a comment