Architecture 解析云代码结构

Architecture 解析云代码结构,architecture,parse-platform,cloud,parse-cloud-code,Architecture,Parse Platform,Cloud,Parse Cloud Code,我正在使用一个社交移动应用程序。我想让云代码具有可伸缩性,但Parse有一些我必须遵守的规则。结构如下: cloud/ main.js other.js otherfile/ someother.js ... ... 只有main.js是必需的,移动客户端只能调用main.js中的函数 在我的客户机中,我使用MVC作为体系结构,但我不确定在我的云代码中应该使用哪种体系结构。我的云代码架构应该如何 是否有我可以使用的通用后端体系结构

我正在使用一个社交移动应用程序。我想让云代码具有可伸缩性,但Parse有一些我必须遵守的规则。结构如下:

cloud/
    main.js
    other.js
    otherfile/
        someother.js
        ...
    ...
只有main.js是必需的,移动客户端只能调用main.js中的函数

在我的客户机中,我使用MVC作为体系结构,但我不确定在我的云代码中应该使用哪种体系结构。我的云代码架构应该如何


是否有我可以使用的通用后端体系结构?

在云代码中,main.js保持原样。所有云代码函数都位于该文件中。没有调制或附加架构

run(名称、数据、选项)是调用Parse-Cloud函数的唯一方法


我自己做了一个结构。但它肯定可以改进

我试图使main.js变得简单。我只添加了在云代码之外调用的函数名

// Include all of the modules
var module1 = require('cloud/folder1/file1.js');
var module2 = require('cloud/folder1/file2.js');
var module3 = require('cloud/folder2/file1.js'); 
var backgroundjob = require('cloud/backgroundjob/background.js'); 

Parse.Cloud.job("startBackgroundJob", backgroundjob.startBackgroundJob);
Parse.Cloud.define("do_this_stuff", module1.thisfunction);
Parse.Cloud.define("do_this_stuff2", module1.notthisfunction);
Parse.Cloud.define("do_that_stuff", module2.thatfunction);
Parse.Cloud.define("do_dat_stuff", module3.datfunction);
在file1.js中,我编写了如下函数

// Include libraries
var utils = require("cloud/utils/utils.js");
var _ = require('underscore');

// Export Modules
module.exports = {
  thisfunction: function (request, response) {
    addComment(request, response);
  },
  thatfunction: function (request, response) {
    getComment(request, response);
  },
};

function addComment(request, response) {
    // write your code here
    var stuff = utils.callThisFunction(param); // This is the usage of another function in another file
    response.success("Comment added"); // or error but do not forget this
} 

function getComment(request, response) {
    // write your code here
    response.success("Got Comment"); // or error but do not forget this
}
我导出了如图所示的模块,因为它使代码更具可读性。我可以看看代码的顶部,看看我可以从这个文件中使用哪些函数。您可以使用


您可以通过在
main.js
旁边创建一个新模块,比如
services.js

require("cloud/services.js");
并在
main.js

require("cloud/services.js");

最后,该文件中定义的所有云函数都将像在
main.js
中一样对您可用。这是因为当你
需要它时,Parse会运行该文件中的所有内容,这基本上意味着你只需要将所有代码分解成一个单独的文件。

我正打算做一个类似的评论。我在几个不同的模块中定义了云功能,Android和iOS应用程序都能找到它们。我在Main.js第5000行左右意识到模块是一条出路!这很有帮助!我进一步做了以下工作:``var CloudFunctions=require('./source/cloud functions.js')。每个(.keys(CloudFunctions)、函数(functionName){Parse.Cloud.define(functionName、CloudFunctions[functionName]);});`这样你就不需要定义每一个了。也适用于作业、保存/删除等