简体   繁体   English

自托管的Parse Platform RESTful API访问

[英]Self-hosted Parse Platform RESTful API access

I'm using Parse for some quick MVP app development to prove some concepts. 我正在使用Parse进行一些快速的MVP应用开发,以证明一些概念。 Everything is working fine and I'm simply trying to extend the abilities of our app by setting up some 3rd party integrations etc. 一切工作正常,我只是在尝试通过设置一些第三方集成来扩展我们应用程序的功能。

I would like to access my Cloud Code functions via the RESTful api, as documented here 我想通过RESTful api访问我的Cloud Code函数,如此处所述

I've changed the server address, but have no luck connecting and pulling the data. 我更改了服务器地址,但是连接和提取数据没有运气。

I am using Node.js to connect to the REST api, which is being hosted on Heroku. 我正在使用Node.js连接到REST api,该api托管在Heroku上。

var options = {
        host: 'https://###############.herokuapp.com',
        port: 443,
        path: '/parse/functions/'+req.param('text'),
        method: 'POST',
        headers: {
            'X-Parse-Application-Id': '##############',
            'X-Parse-REST-API-Key': '###########'
        }
    };
    https.get(options, function(resp){
      resp.on('data', function(chunk){
        //do something with chunk
        res.send(chunk)
      });
    }).on("error", function(e){
      console.log("Got error: " + e.message);
      res.send(e)
    });

So far no luck. 到目前为止没有运气。 Any suggestions? 有什么建议么?

Hard to tell what exactly is wrong without seeing the Parse Server configuration, the Cloud Code function, and more importantly the server's response, but here's what worked for me: 在不查看Parse Server配置,Cloud Code功能以及更重要的是服务器的响应的情况下,很难说出到底是什么错误,但这对我有用:

curl -X POST -H "X-Parse-Application-Id: XYZUASDASDA" -H "X-Parse-REST-API-Key: XYZUASDASDA" -H "Content-Type: application/json" -d '{}' curl -X POST -H“ X-Parse-Application-Id:XYZUASDASDA” -H“ X-Parse-REST-API-Key:XYZUASDASDA” -H“ Content-Type:application / json” -d'{}'
http://localhost:3000/parse/functions/averageStars HTTP://本地主机:3000 /解析/功能/ averageStars

Result: {"result":"Hello"} 结果:{“结果”:“你好”}

Here's my test Cloud Code function: 这是我测试的Cloud Code函数:

Parse.Cloud.define('averageStars', function(request, response) { response.success('Hello'); }); Parse.Cloud.define('averageStars',function(request,response){response.success('Hello');});

As a quick test, I suggest: 作为快速测试,我建议:

  1. Try using CURL 尝试使用CURL
  2. Try the test function above 试试上面的测试功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM