parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Cloud code functions not getting called

Open oyvindvol opened this issue 10 years ago • 8 comments

I have set up parse-server on Heroku, but I am having trouble with the cloud code. I used the parse-server-example, and replaced the contents of main.js with my own:

console.log('##### TEST');

Parse.Cloud.afterSave('SomeClass', function(request) {
  console.log('##### INSIDE AFTER SAVE');
});

And this is my parse-server setup:

var api = new ParseServer({
  databaseURI: 'mongodb://...',
  cloud: __dirname + '/cloud/main.js',
  appId: '...',
  masterKey: '...',
  dotNetKey: '...',
  clientKey: '...',
  fileKey: '...',
  serverURL: 'https://<appname>.herokuapp.com/parse',
  push: {
    ios: [
      {
        pfx: '....p12',
        bundleId: '<bundle-id>',
        production: false
      }, 
      {
        pfx: '....p12',
        bundleId: '<bundle-id>',
        production: true
      }
    ]
  }
});

When i run heroku logs in the terminal i can see the "### TEST" getting printed after start up. But when I save an object of the specified type, nothing is printed in the logs, so it seems that the beforeSave and afterSave isn`t getting called at all.

oyvindvol avatar Feb 12 '16 15:02 oyvindvol

what's your cloud function looks like? Did you really save a 'SomeClass' object in your cloud function?

liangjun-jiang avatar Feb 12 '16 21:02 liangjun-jiang

The SomeClass object is saved from a client. The code I posted is my entire main.js.

oyvindvol avatar Feb 12 '16 21:02 oyvindvol

did you have Parse.serverURL="https://fast-badlands-XXXX.herokuapp.com/parse/";

in your main.js?

jiawenzhang avatar Feb 13 '16 12:02 jiawenzhang

No, the serverURL is set in index.js, in my ParseServer initialization. Is that wrong?

oyvindvol avatar Feb 13 '16 12:02 oyvindvol

Are you sure your parse server instance is receiving that object save and processing it?.. for troubleshooting purposes, it's important to know.. are you using an app Id which is also a parse.com app id? Is the parse app also connected to the same database, etc.. I'd run the server with the environment variable VERBOSE=1 and make sure the save was received.

gfosco avatar Feb 13 '16 21:02 gfosco

No, I am not sure of that, and don`t quite know how to check it. This is the situation:

  • I clicked the Heroku button on the parse-server-example, and set up a Heroku app
  • I started the database migration from parse to my new MongoLab base
  • I copied keys from parse, into my own Parse Server initialisation (appId, masterKey, fileKey, clientKey)
  • I use a client (.NET-client) to make changes to an existing "SomeClass" object (this client connects to the parse database)
  • I verify that the change was made in the parse database, and it was synced to the MongoLab database
  • I thought that at the point the data was synced to the MongoLab instance, the afterSave() would get called
  • I`ve also tried adding records directly to the MongoLab database

oyvindvol avatar Feb 13 '16 21:02 oyvindvol

The .NET SDK would make a call with the dotNetKey, which if you haven't configured would cause a problem. Here's an easy test... Change the appId for your ParseServer instance and also in your .Net app. I recommend removing any clientKey/javascriptKey/dotNetKey/restAPIKey options.

gfosco avatar Feb 14 '16 09:02 gfosco

When going through my .NET client, and not just saving objects directly in the MongoLab database, the cloud functions were called as they should.

oyvindvol avatar Feb 16 '16 11:02 oyvindvol