最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cloud code functions are not executing with Parse server open source API - Stack Overflow

programmeradmin0浏览0评论

So here's my problem, we're developing a mobile app so 5 month ago when we began, we used Parse for our backend solution. Now Parse will die in a few month but luckily, we can still use Parse server by including their API. But after migrating our DB (implying in the process a lot of anger and despair :p) on mongo and hosting the server on AWS, I cannot execute my cloud code anymore. The functions I defined are not found, and with the Parse dashboard not available anymore, I can't check if my cloud funcs are deployed on the server or not. Can someone help me and tell me what I am doing wrong ? And do you guys know another way to check on cloud funcs ? Here's my index.js :

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var math = require('mathjs');

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI
var app = express();
Parse.initialize('XXXXXXX', 'XXXXXX');

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'XXXXXX',
  cloud: './cloud/main.js',
  appId: process.env.APP_ID || 'XXXXXX',
  masterKey: process.env.MASTER_KEY || 'XXXXXX',
  serverURL: '/'
});


var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

app.get('/', function(request, response) {

  Parse.Cloud.run('hello');

});

So here's my problem, we're developing a mobile app so 5 month ago when we began, we used Parse for our backend solution. Now Parse will die in a few month but luckily, we can still use Parse server by including their API. But after migrating our DB (implying in the process a lot of anger and despair :p) on mongo and hosting the server on AWS, I cannot execute my cloud code anymore. The functions I defined are not found, and with the Parse dashboard not available anymore, I can't check if my cloud funcs are deployed on the server or not. Can someone help me and tell me what I am doing wrong ? And do you guys know another way to check on cloud funcs ? Here's my index.js :

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var math = require('mathjs');

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI
var app = express();
Parse.initialize('XXXXXXX', 'XXXXXX');

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'XXXXXX',
  cloud: './cloud/main.js',
  appId: process.env.APP_ID || 'XXXXXX',
  masterKey: process.env.MASTER_KEY || 'XXXXXX',
  serverURL: 'http://parseserver-4w2hk-env.elasticbeanstalk./'
});


var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

app.get('/', function(request, response) {

  Parse.Cloud.run('hello');

});

and my main.js (cloud funcs) :

Parse.Cloud.define('hello', function(req, res) {
  Parse.Cloud.httpRequest({
      url: 'http://www.parse./',
      success: function(httpResponse) {
        response(httpResponse.text);
      },
      error: function(httpResponse) {
        response('Request failed with response code ' + httpResponse.status)
      }
    });
});

Here's the log line, it display a 404 error for the cloud function :

[21/Feb/2016:16:58:56 +0000] "POST /functions/hello HTTP/1.1" 404 29 "-" "node-XMLHttpRequest, Parse/js1.7.1 (NodeJS 4.2.3)"

Thanks in advance ! :)

Share Improve this question asked Feb 21, 2016 at 17:23 Alexandre DI MAMBROAlexandre DI MAMBRO 311 silver badge6 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 4

You should be able to call the function with an HTTP request.

Did you try the sample cloud code:

Parse.Cloud.define('hello', function(req, res) {
  res.success('Hello world!');
});

Note that the default mount path is '/parse' and not '/1' as it was with the parse. service.

For a test using curl:

curl -X POST -H "X-Parse-Application-Id: XXX" -H "X-Parse-REST-API-Key: XXX" http://<your server>/parse/functions/hello

Use cloud: __dirname+'/cloud/main.js', instead of cloud: './cloud/main.js',

So I have some more infos : when I do a curl POST mand on my serverurl/parse/functions/hello, it works, but it gives me "Hello World" as response, so that means that my file main.js has never been uploaded on the cloud code. I am sure it has something to do with my ParseServer configuration, but I dont know what....Maybe it's because of the replicaSet, there might be another way to do it.

Yeah so, I don't know why, when I changed our dev environment and went on the prod, cloud functions were magically executed, so I cloned that env, and now it's working, my cloud funcs are called properly. Ahhhh the wonders of code.. Thanks anyway guys and thank you Ilya for taking some time :)

For hosted parse server you must restart your server every time you add a new cloud function to /cloud/main.js

regards

发布评论

评论列表(0)

  1. 暂无评论