简体   繁体   English

如何解析云代码与解析服务器一起工作?

[英]How does parse cloud code work with parse server?

I am confused after reading Parse's documentation on Cloud Code. 阅读Parse关于Cloud Code的文档后,我很困惑。 They say that Cloud Code is not a Node.js environment. 他们说Cloud Code 不是 Node.js环境。

  • What is the significance to this? 这有什么意义?
  • Will my request to the server still be handled with the node.js engine ( since the actual server uses Node.js & Express)? 我的服务器请求是否仍然使用node.js引擎处理(因为实际的服务器使用Node.js和Express)?
  • How does the cloud code work with the server, are the request going through the server first, than passed to cloud code functions? 云代码如何与服务器一起工作,请求首先通过服务器,而不是传递给云代码函数?

Eg when I call a cloud function from the client (In this case a iOS app). 例如,当我从客户端调用云功能时(在这种情况下是iOS应用程序)。

PFCloud.callFunctionInBackground("testCloud", withParameters: [:]) {
            (response: AnyObject?, error: NSError?) -> Void in
            if (error == nil) {
                if let testRespones = response as? String{
                    print(testRespones)
                } 
            } else {
                   print(error)
              } 
}

My parse server is currently hosted on Heroku. 我的解析服务器目前托管在Heroku上。

Any insight would be greatly appericated. 任何洞察力都会非常明显。

Your Cloud Code is literally just a javascript file running in a node.js server instance. 您的Cloud Code实际上只是在node.js服务器实例中运行的javascript文件。 When you make a request to the server for your Cloud Code your parse-server express app routes these request, denoted by /cloud, to your file in your cloud directory. 当您向服务器请求Cloud Code时,您的parse-server express应用程序会将这些请求(由/ cloud表示)路由到您的云目录中的文件。 In order for this to work you must set your cloud variable in your ParseServer object in index.js. 为此,您必须在index.js中的ParseServer对象中设置您的云变量。 Something like this 像这样的东西

cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js'

So basically when you call a cloud function you're calling the cloud variable in your parse-server which routes you to 'parse-server-directory/cloud/main.js' and finds your function and returns some kind of response. 所以基本上当你调用云函数时,你在你的parse-server中调用了云变量,它将你引导到'parse-server-directory / cloud / main.js'并找到你的函数并返回某种响应。

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

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