【发布时间】:2021-07-11 04:35:06
【问题描述】:
我在使用 Parse-server 的 Back4App 中使用 Node.js。我正在尝试从 openweathermap.org 获取天气预报。但是我得到一个空的返回值?我不明白为什么? 当在前端与颤振一起使用时,它可以在相同的 url 上完美运行。
var _weather;
Parse.Cloud.define("WD", (request) => {
var http = require('http');
var options = {
hostname: 'api.openweathermap.org',
path: '/data/2.5/forecast?q=Malaga&units=metric&appid=mykey'
};
callback = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
_weather = JSON.parse(str);
});
}
http.request(options, callback).end();
return _weather;
});
【问题讨论】:
标签: node.js parse-server back4app