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(); }