generated from staticwebdev/vanilla-basic
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
128 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
const fetch = require("node-fetch"); | ||
|
||
module.exports = async function (context, req) { | ||
context.log('JavaScript HTTP trigger function processed a request.'); | ||
|
||
const name = (req.query.name || (req.body && req.body.name)); | ||
const responseMessage = name | ||
? "Hello, " + name + ". This HTTP triggered function executed successfully." | ||
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."; | ||
|
||
context.res = { | ||
// status: 200, /* Defaults to 200 */ | ||
body: responseMessage | ||
}; | ||
} | ||
try { | ||
const { dep, arr, date, time } = req.body; // 매개변수로부터 위도, 경도 정보를 받음 | ||
|
||
const call_command = `python3 ./onecall_script/chat.py ${dep} ${arr} ${date} ${time}`; | ||
|
||
const execSync = require('child_process').execSync; | ||
const resultBuffer = execSync(call_command, { encoding: 'utf-8' }); | ||
const result = resultBuffer.toString(); | ||
|
||
var jsonData = "" | ||
try { | ||
jsonData = JSON.parse(result); | ||
} catch (error) { | ||
console.error('JSON 파싱 오류:', error.message); | ||
} | ||
|
||
context.res.json({ | ||
// status: 200, /* Defaults to 200 */ | ||
res: jsonData | ||
}); | ||
|
||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
|
||
context.res = { | ||
status: 500, | ||
body: { error: "Error fetching data" }, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters