Skip to content

addParseCloud in ParseServer init function #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

shoe116
Copy link

@shoe116 shoe116 commented Feb 28, 2016

I try to add my function to triggers by ParseCloud.define but failed, because Parse.applicationId is null.

I think the function addParseCloud should be call in ParseServer that is given the appId.

@flovilmart
Copy link
Contributor

@shoe116 what version of parse-server are you using? This should be fixed since the Hooks API merge a few days ago. Can you try with your parse-server dependency in package.json set to "parseplatfrom/parse-server#master" ?

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

@flovilmart I using master branch's "parse-server" git fetch from this repository yesterday.
Latest commit is here.

$git log
commit bd89338b39d384ab795ab39659b705be90ca7d2f
Merge: 97d6e9d 3106508
Author: Drew 
Date:   Sat Feb 27 12:04:39 2016 -0800

    Merge pull request #696 from mcdonamp/gcp-logo

    Adding the GCP logo and quickstart

bd89338

@flovilmart
Copy link
Contributor

Alright, do you notice the same behaviour removing the addParseCloud() you added at the bottom?

also can you add in spec/cloud/main.js a

Parse.Cloud.define("echoKeys", function(req, res) {

    return res.success({
        applicationId: Parse.applicationId,
        javascriptKey: Parse.javascriptKey,
        masterKey: Parse.masterKey });

});

And an according test to make sure no regression occurs in the future?

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

@flovilmart I've added a sample function like

ParseCloud.define("hello", 
      function(req, res){res.success("Hello World");}
      ,function(req){return true}
);

module.exports = ParseCloud;

on the end of src/cloud-code/Parse.Cloud.js.

When I remove the addParseCloud() function at the bottom, call return error

{"code":141,"error":"Invalid function."}

Please excuse me if I misunderstood.

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

Sorry, I don't check spec/cloud/main.js and I add the sample code in src/cloud-code/Parse.Cloud.js directry.

@flovilmart
Copy link
Contributor

You should not modify src/cloud-code/Parse.Cloud.js to add a trigger there as this will be compiled for everyone. You should really add the code in spec/cloud/main.js as this is what's loaded when running the tests.

addParseCloud simply adds the ability to define the functions and hooks. No ParseCloud.define should be called here

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

@flovilmart OK, I've understood you said "the same behaviour removing the addParseCloud() I add."

@flovilmart
Copy link
Contributor

stay tuned I'm adding a unit test to make sure the keys are properly set when calling a Cloud Function

@flovilmart
Copy link
Contributor

btw, do you use parse-server as a dependency or directly the repository?

@flovilmart
Copy link
Contributor

check #714

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

I'm just an user of parse.com but I liked this product so try to read and write some code for my app's migration on parse.com.

@flovilmart
Copy link
Contributor

no problem @shoe116 :)

tell me, when you say:

I try to add my function to triggers by ParseCloud.define but failed, because Parse.applicationId is null.

You mean you added your trigger to src/cloud-code/Parse.Cloud.js right?

That is not the expected way to add triggers.

You should pass a cloud option to the new ParseServer({}) call see here: https://github.com/parseplatform/parse-server/#basic-options

@shoe116
Copy link
Author

shoe116 commented Feb 28, 2016

@flovilmart yes, I add my sample trigger on src/cloud-code/Parse.Cloud.js.

So, I have to set cloud param as spec/cloud/main.js? Ok, I will try.

@flovilmart
Copy link
Contributor

@shoe116 so the sample trigger has nothing to do in src/cloud-code/Parse.Cloud.js!! This is not the place to put the trigger!

So, I have to set cloud param as spec/cloud/main.js.

Yes! look at spec/helper.js, you'll see the configuration options pass the cloud: ' spec/cloud/main.js'.
For you that would probably be cloud: "./cloud/main.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants