
module.exports = function(app, fs)
{
     app.get('/',function(req,res){
    	 res.render('index.html')
     });
     app.get('/search', function (req, res) {
    	 var client_id = 'OJgN42xxZiJXpnZtCH1j';
    	 var client_secret = 'crXggqJhhW';
    	 var api_url = 'https://openapi.naver.com/v1/search/blog?query=' + encodeURI(req.query.query); // json 결과
//   	var api_url = 'https://openapi.naver.com/v1/search/blog.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);
    			 var body = JSON.parse(body); 
    			 res.render('search', {
					title: req.query.query + " 키워드",
					values: body.items
    			 })
    		 } else {
    			 res.status(response.statusCode).end();
    			 console.log('error = ' + response.statusCode);
    		 }
    	 });
	});
}