Search code examples
javascriptparse-platformparse-server

Parse-server problems with cloud code.


I've deployed a parse-server to heroku (mLab.com as database) but have some problems with cloud code.

When calling the "hello" function, everything works fins.

When calling the "testFunction", which in turns makes a query request, I get this error:

  XMLHttpRequest cannot load https://xxxxx.herokuapp.com/parse/functions/testFunction. 
    No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://127.0.0.1:51488' is therefore not allowed access. 
The response had HTTP status code 503.

Been playing around with cors without any luck. Any suggestions would be very appreciated.

------------ CLIENT ------------
Parse.initialize("xxxxxx");
Parse.serverURL = 'https://xxxxx.herokuapp.com/parse/'

Parse.Cloud.run('hello').then(function (result) {
    console.log(result);
});

Parse.Cloud.run('testFunction').then(function (result) {
    console.log(result);
});

------------ SERVER -----------  

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

Parse.Cloud.define("testFunction", function (request, response) {
    var query = new Parse.Query("Jobs");
    query.find().then(function (result) {
        response.success("Success: " + result);
    });
});

Solution

  • Find out the problem. I had forgot to add the SERVER_URL in environmental variables in heroku.