Showing
1 changed file
with
0 additions
and
150 deletions
app.js
deleted
100644 → 0
| 1 | -var express = require('express') | ||
| 2 | - , http = require('http') | ||
| 3 | - , path = require('path'); | ||
| 4 | - | ||
| 5 | -var request = require('request'); | ||
| 6 | - | ||
| 7 | -var bodyParser = require('body-parser') | ||
| 8 | - , cookieParser = require('cookie-parser') | ||
| 9 | - , static = require('serve-static') | ||
| 10 | - , errorHandler = require('errorhandler'); | ||
| 11 | - | ||
| 12 | - | ||
| 13 | -var expressSession = require('express-session'); | ||
| 14 | - | ||
| 15 | -var app = express(); | ||
| 16 | - | ||
| 17 | - | ||
| 18 | -app.set('port', process.env.PORT || 3000); | ||
| 19 | - | ||
| 20 | -// body-parser를 이용해 application/x-www-form-urlencoded 파싱 | ||
| 21 | -app.use(bodyParser.urlencoded({ extended: false })) | ||
| 22 | - | ||
| 23 | -// body-parser를 이용해 application/json 파싱 | ||
| 24 | -app.use(bodyParser.json()) | ||
| 25 | - | ||
| 26 | -// public 폴더를 static으로 오픈 | ||
| 27 | -app.use('/public', static(path.join(__dirname, 'public'))); | ||
| 28 | - | ||
| 29 | -// cookie-parser 설정 | ||
| 30 | -app.use(cookieParser()); | ||
| 31 | - | ||
| 32 | -// 세션 설정 | ||
| 33 | -app.use(expressSession({ | ||
| 34 | - secret:'my key', | ||
| 35 | - resave:true, | ||
| 36 | - saveUninitialized:true | ||
| 37 | -})); | ||
| 38 | - | ||
| 39 | - | ||
| 40 | -// 라우터 객체 참조 | ||
| 41 | -var router = express.Router(); | ||
| 42 | - | ||
| 43 | -router.route('/process/map').get(function(req, res){ | ||
| 44 | - console.log('process/map 호출됨'); | ||
| 45 | -}); | ||
| 46 | - | ||
| 47 | - | ||
| 48 | -app.use('/', router); | ||
| 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 | - | ||
| 144 | -// Express 서버 시작 | ||
| 145 | -http.createServer(app).listen(app.get('port'), function(){ | ||
| 146 | - console.log('서버가 시작되었습니다. 포트 : ' + app.get('port')); | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - }); | ||
| 150 | - |
-
Please register or login to post a comment