0
Getting CORS error when calling cloud function in back4app.

Error:     

Access to XMLHttpRequest at 'https://parseapi.back4app.com/functions/hello' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access- Control- Allow-Origin' header is present on the requested resource.

In client code cloud function implemented in home page 

 home.page.ts:

 Parse.Cloud.run('hello').then(function (ratings) {

   console.log("updated");

 }).catch((error) => {

   console.log(error);

   console.log("fail"); 

 });

 Cloud function:

In back4app added main.js file with cloud code implementation

  main.js:

 Parse.Cloud.define('hello', function(req, res) {

   Parse.Cloud.useMasterKey();

   return 'Hi';    
 });
Tejaswini
  • 3
  • 2

1 Answers1

0

It can be related to the Parse Server version.

Can you please take a look to check what is the Parse Server version that you are using? Please, find this info following this guide.

If it is 2.X, you must deploy a function with the structure below:

main.js:

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

The code Parse.Cloud.useMasterKey(); is deprecated. Read more here.

If it is the 3.X, you can deploy something like:

Parse.Cloud.define('hello', (req) => {    
   return 'Hello';
});
  • Check if you have initialized the correct keys on your frontend side.

If it still doesn't work, please contact the Back4App team in the live chat =D

nataliec
  • 502
  • 4
  • 14