在使用 Moralis 云功能时遇到问题
Having trouble with Moralis cloud function
下面的函数return什么都没有return一个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;
});
下面的函数return什么都没有return一个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;
});