The*_*ist 9 architecture cloud parse-platform parse-cloud-code
我正在将Parse Cloud Code用于社交移动应用程序.我想让云代码可扩展,但Parse有一些我必须遵守的规则.结构如下:
cloud/
main.js
other.js
otherfile/
someother.js
...
...
Run Code Online (Sandbox Code Playgroud)
只有main.js是必需品,移动客户端只能调用main.js中的函数.
在我的客户端,我使用MVC作为架构,但我不确定我应该在我的云代码中使用什么样的架构.我的云代码架构应该如何?
我可以使用一般的后端架构吗?
The*_*ist 12
我自己做了一个结构.但它肯定可以改善.
我试图让我的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);
Run Code Online (Sandbox Code Playgroud)
在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
}
Run Code Online (Sandbox Code Playgroud)
我导出的模块如图所示,因为它使代码更具可读性.我可以查看代码的顶部,看看我可以从这个文件中使用哪些函数.您可以使用docs导出样式.
exports.addComment = function(request, response) {
// your code
response.success();
}
Run Code Online (Sandbox Code Playgroud)