Where to write cloud code on server?

Hello Team, I have a basic question,
I have install Parse server and parse dashboard on ubuntu18.04. and make service to start parse server and dashboard using global command nd pass config along with that.

Now I want to know where Should I write the cloud function?

where is it globally installed so I can upload my function over there or is there any way to write cloud code using the dashboard or anything else?

Pardon for asking this basic question but I am a beginner to parse server.

I have a scenario where Super-admin( a user from _user class) can create another user and can also modify created user.

So after search, I found by creating cloud code and passing useMasterkey setting in that I can achieve that. So that’s why I am asking here

Can loggedin user ( who is super admin) can modify other user info ? by passing authenticated user session or something like that?

You will actually have to create a cloud code function for this scenario. You can write your cloud code functions anywhere in your server and pass the file location to Parse Server using the cloud option. See the complete list of options here: ParseServerOptions - Documentation

1 Like

thanks for the reply I will try it out.

Hi @davimacedo ,
I have tried to upload using main file and passing cloud path in config file and sample code is bellow
Parse.Cloud.define(‘hello’, function(req, res) {
res.success(“World”)
});

access this code on react app as well as on parse dashboard JS console
const ratings = await Parse.Cloud.run(“hello”);
console.log(“ratings” , ratings)

But am getting below error

“Error”:{

3 items

“message”:

string"certificate has expired"

“name”:

string"Error"

“stack”:

string"Error: certificate has expired at handleError (http://dev.waariwater.com:4040/bundles/dashboard.bundle.js:2:1530148) at async eval (eval at (http://dev.waariwater.com:4040/bundles/dashboard.bundle.js:2:3061190), :10:17)"

And on react app

Request on Request URL:

http://38.xx.xx.xx:1337/parse/functions/hello
result

  1. {code: 141, error: “certificate has expired”}

  2. code: 141

  3. error: “certificate has expired”

will cloud code run on plain HTTP as I am using it ?
What thing I am missing here to access cloud code ?

What’s your version of parse server? I think you are using the wrong cloud code style. Should be something like this: Cloud Code Guide | Parse

Anyways, this error is strange. Are the other api calls working correctly?

Hi , I think I am running parse on the latest version only just installed it a couple of months ago ,
I have also tried to change the code according to the guide but it is not working. it works fine in a local environment.

Yes, other API call works fine I am using JS SDK in react project.
So other API call on same plain HTTP but not this one
here is my config file
{
“appName”: “---------”,
“databaseURI”: “-------”,
“appId”: “-------”,
“masterKey”: “---------”,
“serverURL”: “--------”,
“publicServerURL”: “--------”,
“port”: xxxx,
“cloud”: “/username/cloudcodefolder/main.js”
}

Is there any config issue or does Cloud code only work with HTTPS or something like that?

It shouldn’t have any restriction by default. You can inspect your browser network and see the request that the dashboard is doing.

1 Like

Here is Network call for cloud function and for normal class access

for normal class it is working but in case of cloud function there is some issue may be some short of config I missing to write cloud code or passing in config file or smoething like that ?

in past someone also reported on stackoverflow but not answerd I think I am having same issue

Can you share your current cloud code?

1 Like

Hi @davimacedo Thanks for the quick response
My Cloud code started

my cloude code is
Parse.Cloud.define(“hello”, async (request) => {
return “World”;
});

I did create a webhook Function with some dummy URL in it
image

I deleted this hook and CC Strated working
Can you help me that how to use webhook using the dashboard what is is the use of that Or do we need to upload our cloud function manually only ?

What are you trying to do exactly? Cloud code functions work alone. The webhook can be used to hook a cloud code function to an external server. In this case, it will basically ignore any cloud you may have as it will pass your request to the external server.

I am trying to update the user class using a logged-in user As I have a Super-admin panel where the super admin can create / update and delete other user as well.
So to achieve that I was writing cloud code . But It was not working
By mistake, I created a webhook pointing to a random/fake URL.
And as you said if webhook is there then my local cloud function does not work.
After deleting that webhook from parse-dashboard my cloud code started working. :handshake:

Once again thanks for quick response