下面的函数在应该返回json字符串的时候什么也没有返回
Moralis.Cloud.define("getMeta", async (request,uri) => {
const logger = Moralis.Cloud.getLogger();
let results;
results = await Moralis.Cloud.httpRequest({
url: 'https://defi-city.com/api/city/463',
followRedirects: true,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}).then(function(httpResponse) {
results=httpResponse.text;
logger.info("over here"+results);
logger.info(httpResponse.text);
}, function(httpResponse) {
logger.info('Request failed with response code ' + httpResponse.status);
});
logger.info("end"+results);
return await results;
});
let mData = await Moralis.Cloud.run("getMeta",uri);
添加return
解决了问题
Moralis.Cloud.define("getMeta", async (request, uri) => {
const logger = Moralis.Cloud.getLogger();
let results;
results = await Moralis.Cloud.httpRequest({
url: "https://defi-city.com/api/city/463",
followRedirects: true,
headers: {
"Content-Type": "application/json;charset=utf-8",
},
}).then(
function (httpResponse) {
results = httpResponse.text;
logger.info("over here" + results);
logger.info(httpResponse.text);
return results; //There
}
);
logger.info("end" + results);
return results;
});