임승현

Merge branch 'feature/Search' into 'master'

Feature/search

First Merge from feature/Search to master

See merge request !7
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!');
});
{
"dependencies": {
"express": "^4.18.1",
"request": "^2.88.2"
}
}