简体   繁体   English

如何在解析服务器上创建和调用云代码功能?

[英]How to create and call cloud code functions on parse-server?

I'm trying to run some very basic cloud code function on my parse-server and I get the same error every time: 141 Invalid function. 我试图在我的解析服务器上运行一些非常基本的云代码功能,每次都收到相同的错误:141无效的功能。 I'm just adding a main.js file with my function in the cloud directory and trying to call it using Postman, but it looks like the file is not even called. 我只是将main.js文件和我的函数添加到云目录中,并尝试使用Postman进行调用,但看起来甚至没有调用该文件。

I've tried locally and on a docker, if the function exist or not I get the same result, and tried restarting the docker container after adding the code. 我已经在本地和docker上尝试过,如果函数存在或不存在,我会得到相同的结果,并尝试在添加代码后重新启动docker容器。 I also tried adding a body to the request with parameters like master and functionName. 我还尝试使用诸如master和functionName之类的参数向请求添加主体。

Here's my cloud code function (cloud/main.js): 这是我的云代码功能(cloud / main.js):

Parse.Cloud.define('hello', function(req, res) {
  return "function called";
});

Calling the function with a POST request on https://myurl/parse/functions/hello and getting: 通过POST请求在https:// myurl / parse / functions / hello上调用函数,并获得:

{
    "code": 141,
    "error": "Invalid function: \"hello\""
}

The response object has been removed from Parse Server Cloud Code post v3.0.0 . response对象已从Parse Server Cloud Code版本v3.0.0

Your Cloud Code function should look like this... 您的云代码功能应如下所示...

Parse.Cloud.define("hello", async (request) => {
  return "function called";
});

Please read the migration guide for more details on updating your cloud code to v3.0.0 or above. 请阅读迁移指南,以获取有关将云代码更新到v3.0.0或更高版本的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM