diff --git a/api/findroad/index.js b/api/findroad/index.js index 2deaa4d..c0bdedf 100644 --- a/api/findroad/index.js +++ b/api/findroad/index.js @@ -32,6 +32,7 @@ module.exports = async function (context, req) { console.log(JSON.stringify(json_response, null, 2)); let itineraryText = ''; + var text_counter = 0; for (const itinerary of json_response['metaData']["plan"]["itineraries"]) { const legs = itinerary.legs || []; @@ -44,29 +45,31 @@ module.exports = async function (context, req) { for (let i = 0; i < lanes.length; i++) { const route = lanes[i].route || `No route information for Lane ${i}`; - if (route.startsWith('SRT') || route.startsWith('KTX') || route.startsWith('ITX') || route.startsWith('무궁화')) { + if (route.startsWith('KTX')) { const departure_station = leg["start"]["name"]; const arrival_station = leg["end"]["name"]; console.log(`야삐 Departure Station: ${departure_station}`); console.log(`야삐 Arrival Station: ${arrival_station}`); console.log(`야삐 Route: ${route}`); - - itineraryText += `Departure Station: ${departure_station}\n`; - itineraryText += `Arrival Station: ${arrival_station}\n`; - itineraryText += `Route: ${route}\n\n`; - + if (text_counter == 0) { + itineraryText += `{"dep": "${departure_station}",`; + itineraryText += `"arr": "${arrival_station}",`; + itineraryText += `"Route": "${route}",}`; + + text_counter += 1; + } } } } } } - - context.res.body = { itineraryText }; + console.log(itineraryText) + context.res.body = JSON.parse(itineraryText); context.res = { status: 200, - body: { itineraryText }, // 직접 context.res.body에 itineraryText를 넣어줌 + body: JSON.parse(itineraryText), // 직접 context.res.body에 itineraryText를 넣어줌 headers: { 'Content-Type': 'application/json' } diff --git a/api/ktx_schedule/index.js b/api/ktx_schedule/index.js index 0d70bbc..ff0aaae 100644 --- a/api/ktx_schedule/index.js +++ b/api/ktx_schedule/index.js @@ -2,12 +2,9 @@ const axios = require('axios'); module.exports = async function (context, req) { - const dep = "동대구"; - const arr = "서울"; - const date = "20231112"; - const time = "120000"; + const {dep, arr, date, time} = req.body; - const call_command = `python3 ./ktx_schedule/ktx_api.py ${dep} ${arr} ${date} ${time}`; + const call_command = `python ./ktx_schedule/ktx_api.py ${dep} ${arr} ${date} ${time}`; // console.log(call_command); const execSync = require('child_process').execSync; @@ -24,8 +21,11 @@ module.exports = async function (context, req) { console.error('JSON 파싱 오류:', error.message); } - context.res.json({ - // status: 200, /* Defaults to 200 */ - res: jsonData - }); + context.res = { + status: 200, + body: jsonData, + headers: { + 'Content-Type': 'application/json' + } + }; } \ No newline at end of file diff --git a/package.json b/package.json index 3d8110f..382f5e1 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,5 @@ "node-fetch": "^2.7.0", "swa": "^0.0.1" }, - "type":"module" + "type": "module" } diff --git a/src/index.html b/src/index.html index 285802d..8084fe2 100644 --- a/src/index.html +++ b/src/index.html @@ -204,6 +204,7 @@

Vanilla JavaScript App

@@ -256,8 +258,9 @@

Vanilla JavaScript App

}), }) ).json(); - + console.log(text.body); document.querySelector('#findroad').textContent = text; + } catch (error) { console.error('주소 변환 및 API 호출에 실패하였습니다:', error); }