英文:
How to make a http request with axios from inside Parse Cloud Code function?
问题
我尝试在Parse Cloud Code函数内发出请求。我的尝试如下:
const axios = require('axios').default;
Parse.Cloud.define("loginSchool", async (request) => {
test = await axios({
method: 'get',
url: 'https://google.com'
});
return(test);
});
我可以使用curl调用该函数,但结果只返回Bad Gateway
。
我正在使用Parse版本5.2.3的Back4App。
在Cloud Code函数内正确使用axios进行HTTP请求的方法是什么?
英文:
I'm trying to make a request from inside a Parse Cloud Code function. My attempt looks likes this:
const axios = require('axios').default;
Parse.Cloud.define("loginSchool", async (request) => {
test = await axios({
method: 'get',
url: 'https://google.com'
});
return(test);
});
I can call the function via curl but it only returns Bad Gateway
as result.
I'm using Back4App with Parse Version 5.2.3.
What is the correct way to use axios inside a cloud code function for making a http request?
答案1
得分: 0
axios不会默认包含在Parse云代码中,所以您需要手动安装它。例如,如果您在本地开发,请在云文件夹中运行 npm install axios
,然后部署云文件夹,包括 node_modules
文件夹。
另外,您也可以尝试下载axios模块,然后通过云代码仪表板上传它。但对我来说,设置本地的parse_server 对我有很大帮助,因为我能更快地查看日志,从而确定问题。
英文:
Found the problem by myself but maybe it helps someone else.
axios is not included as dependency by default inside parse cloud code. Therefore you need to install it. e.g. if you develop locally run npm install axios
in the cloud folder and afterwards deploy the cloud folder, including the node_modules
folder.
Alternativly I imagine you could download the axios module and upload it via the Dashboard for Cloud Code. But for me setting up a local parse_server helped me a lot because I could see the logs more quickly and therefore determine the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论