ฉันมีปัญหาบางอย่างขณะใช้งาน IBM Cloud Function นี้:
/**
*
* main() will be run when you invoke this action
*
* @param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* @return The output of this action, which must be a JSON object.
*
*/
function main(params) {
const https = require('https');
https.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
ปัญหาของฉันคือการเรียกใช้ฟังก์ชันนี้ครั้งแรก (อย่างน้อย 3-4 แรก) ไม่มีผลลัพธ์ การโทรครั้งต่อไปทำงานอย่างถูกต้องและบันทึกจะแสดงอย่างถูกต้อง ฉันจะแก้ไขพฤติกรรมที่คาดเดาไม่ได้นี้ได้อย่างไร แน่นอนว่าฉันต้องการดึงข้อมูลของฉันเมื่อเรียกใช้ฟังก์ชันนี้ครั้งแรก ขอบคุณ.