在开源解析服务器上实现云代码
问题描述:
我正在使用新的Parse Server开发应用程序.我已经研究了很多,但无法弄清楚.我想运行一些服务器端代码(云代码),但我什至无法弄清楚如何使用Heroku和Mongo创建云代码文件.非常感谢您的帮助!
I am developing an app using the new Parse Server. I have researched quite a bit, but cannot figure this out. I want to run some server side code (Cloud Code) but I cannot figure out how to even create a Cloud Code file using Heroku and Mongo. Any help is very much appreciated!
答
在应用程序的根目录中,创建一个云文件夹,并在该文件夹中创建一个main.js文件,并将示例内容复制到该文件中
In the root of app create a cloud folder and create a main.js file in that folder and copy the sample contents in the file
Parse.Cloud.define('hello', function(req, res) {
res.success('Hi');
});
然后在您的Index.js中提及该文件在config中的路径
Then in your Index.js mention the path of this file in config
var api = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev',
cloud: __dirname + '/cloud/main.js',
appId: 'myAppId',
masterKey: '', //Add your master key here. Keep it secret!
serverURL: 'http://localhost:1337' // Don't forget to change to https if needed
});