최현영

app.js

Showing 1 changed file with 98 additions and 1 deletions
1 var express = require('express') 1 var express = require('express')
2 , http = require('http') 2 , http = require('http')
3 , path = require('path'); 3 , path = require('path');
4 +
5 +var request = require('request');
4 6
5 var bodyParser = require('body-parser') 7 var bodyParser = require('body-parser')
6 , cookieParser = require('cookie-parser') 8 , cookieParser = require('cookie-parser')
...@@ -12,6 +14,7 @@ var expressSession = require('express-session'); ...@@ -12,6 +14,7 @@ var expressSession = require('express-session');
12 14
13 var app = express(); 15 var app = express();
14 16
17 +
15 app.set('port', process.env.PORT || 3000); 18 app.set('port', process.env.PORT || 3000);
16 19
17 // body-parser를 이용해 application/x-www-form-urlencoded 파싱 20 // body-parser를 이용해 application/x-www-form-urlencoded 파싱
...@@ -36,7 +39,7 @@ app.use(expressSession({ ...@@ -36,7 +39,7 @@ app.use(expressSession({
36 39
37 // 라우터 객체 참조 40 // 라우터 객체 참조
38 var router = express.Router(); 41 var router = express.Router();
39 - 42 +
40 router.route('/process/map').get(function(req, res){ 43 router.route('/process/map').get(function(req, res){
41 console.log('process/map 호출됨'); 44 console.log('process/map 호출됨');
42 }); 45 });
...@@ -44,6 +47,100 @@ router.route('/process/map').get(function(req, res){ ...@@ -44,6 +47,100 @@ router.route('/process/map').get(function(req, res){
44 47
45 app.use('/', router); 48 app.use('/', router);
46 49
50 +var url1 = 'http://data.ex.co.kr/openapi/odtraffic/trafficAmountByCongest';
51 +var queryParams1 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
52 +queryParams1 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
53 +
54 +request({
55 + url: url1 + queryParams1,
56 + method: 'GET'
57 +}, function (error, response, body) {
58 + console.log('Status', response.statusCode);
59 + console.log('Headers', JSON.stringify(response.headers));
60 + console.log('Reponse received', body);
61 + var obj = JSON.parse(body);
62 + console.log(obj);
63 + console.log(obj.list[0])
64 +});
65 +
66 +
67 +
68 +var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast';
69 +var queryParams2 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
70 +queryParams2 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
71 +
72 +request({
73 + url: url2 + queryParams2,
74 + method: 'GET'
75 +}, function (error, response, body) {
76 + console.log('Status', response.statusCode);
77 + console.log('Headers', JSON.stringify(response.headers));
78 + console.log('Reponse received', body);
79 + var obj = JSON.parse(body);
80 + console.log(obj);
81 + console.log(obj.list[0])
82 +});
83 +
84 +var url3 = 'http://data.ex.co.kr/openapi/trafficapi/trafficAll';
85 +var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
86 +queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
87 +
88 +request({
89 + url: url3 + queryParams3,
90 + method: 'GET'
91 +
92 +}, function (error, response, body) {
93 + console.log('Status', response.statusCode);
94 + console.log('Headers', JSON.stringify(response.headers));
95 + console.log('Reponse received', body);
96 + var obj = JSON.parse(body);
97 + console.log(obj);
98 + console.log(obj.trafficAll[0]);
99 +});
100 +
101 +
102 +var url4 = 'http://data.ex.co.kr/openapi/trafficapi/trafficRegion';
103 +var queryParams4 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
104 +queryParams4 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
105 +
106 +request({
107 + url: url4 + queryParams4,
108 + method: 'GET'
109 +
110 +}, function (error, response, body) {
111 + console.log('Status', response.statusCode);
112 + console.log('Headers', JSON.stringify(response.headers));
113 + console.log('Reponse received', body);
114 + var obj = JSON.parse(body);
115 + console.log(obj);
116 + console.log(obj.trafficRegion[0]);
117 +});
118 +
119 +
120 +
121 +var url5 = 'http://data.ex.co.kr/openapi/business/conveniServiceArea';
122 +var queryParams5 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
123 +queryParams5 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json'); /* */
124 +
125 +request({
126 + url: url5 + queryParams5,
127 + method: 'GET'
128 +
129 +}, function (error, response, body) {
130 + console.log('Status', response.statusCode);
131 + console.log('Headers', JSON.stringify(response.headers));
132 + console.log('Reponse received', body);
133 + var obj = JSON.parse(body);
134 + console.log(obj);
135 + console.log(obj.list[0]);
136 +});
137 +
138 +
139 +
140 +
141 +
142 +
143 +
47 // Express 서버 시작 144 // Express 서버 시작
48 http.createServer(app).listen(app.get('port'), function(){ 145 http.createServer(app).listen(app.get('port'), function(){
49 console.log('서버가 시작되었습니다. 포트 : ' + app.get('port')); 146 console.log('서버가 시작되었습니다. 포트 : ' + app.get('port'));
......