app.js
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var express = require('express');
var config = require('./config.json')
var app = express();
var client_id = config.SearchClientID;
var client_secret = config.SearchClientSecret;
var SearchWord;
var MovieSearchParse;
var movietitlelist;
var movielist;
app.post('/search/movie', function (req, res) {SearchWord = req.query.query; res.send(SearchWord)})
app.get('/search/movie', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/search/movie?query=' + encodeURI(SearchWord);
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'});
MovieSearchParse = JSON.parse(body);
//movietitlelist =MovieSearchParse.items[0].title.replace(/<[^>]*>?/g, '');
movietitlelist = MovieSearchParse.items.map((x)=>{
x.title = x.title.replace(/<[^>]*>?/g, '');
return x.title;
});
movielist = MovieSearchParse.items.map((x)=>{
x.title = x.title.replace(/<[^>]*>?/g, '');
return x;
});
console.log(movielist);
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/movie?query=검색어 app listening on port 3000!');
});