architecture - 解析云代码结构

标签 architecture parse-platform cloud parse-cloud-code

我正在使用 Parse Cloud Code用于社交移动应用程序。我想让云代码可扩展,但 Parse 有一些我必须遵守的规则。结构如下:

cloud/
    main.js
    other.js
    otherfile/
        someother.js
        ...
    ...

只有 main.js 是必需的,移动客户端只能调用 main.js 中的函数。

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

是否有我可以使用的通用后端架构?

最佳答案

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

我试图让我的 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
}

我导出了如图所示的模块,因为它使代码更具可读性。我可以看看代码的顶部,看看我可以从这个文件中使用哪些函数。您可以使用 docs export style .
exports.addComment = function(request, response) {
    // your code
    response.success();
}

关于architecture - 解析云代码结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28129613/

相关文章:

git - 滥用 Git 来实现事件存储架构?

angular - Angular2的微服务架构

Java:如何创建一个返回大数据文件每一行的迭代器(columnList)的通用方法

c# - 在哪里保存我想在多个 ViewModel 之间共享的对象实例

docker - 如何将 GCP > 容器注册表身份验证 key 添加到 Docker config.json?

javascript - 解析无法检索用户电子邮件

ios - 解析 : One app on parse. com 将被多个 iOS 应用程序访问。它有效吗?

ios - 解析 Swift : User relations with a "friends request"

deployment - 无法下载云服务测试服务调用中实例 abc_webrole_IN_0 的 RDP 文件

cloud - 云计算和分布式计算的区别?