解析云服务器的服务器问题。

时间:2016-04-28 08:39:34

标签: javascript parse-platform cors parse-server

我已经将一个解析服务器部署到heroku(mLab.com作为数据库)但是在云代码方面存在一些问题。

当打电话给"你好"功能,一切都工作鳍。

当调用" testFunction",它反过来发出查询请求时,我收到此错误:

  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.

在没有任何运气的情况下一直在玩cors。 任何建议将非常感激。

------------ 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);
    });
});

1 个答案:

答案 0 :(得分:1)

找出问题所在。我忘了在heroku的环境变量中添加SERVER_URL。