Parse + Heroku Query 500 Error

馋奶兔 提交于 2019-12-08 05:34:21

问题


I used Parse's CLI with the new Heroku integration to create the scaffold NodeJS project (parse new).

The example cloud function it gives you is:

// Hello
Parse.Cloud.define('hello', function(request, response) {    

  response.success('Hello world! ' + (request.params.a + request.params.b));

});

I can hit this route with the following CURL command and everything works fine:

curl -X POST \
 -H "X-Parse-Application-Id: b8qPYS4SLSz0WoSWXlWeQosmF2jJPUPydetg3esR" \
 -H "X-Parse-REST-API-Key: TOJLbfbNXSQcBdDVnU0MnKVu7SyamQvZmorHL5iD" \
 -H "Content-Type: application/json" \
 -d '{"a": "Adventurous ", "b": "Parser"}' \
 https://api.parse.com/1/functions/hello

But then I added a new Class to my Parse Data, inserted a row, and tried to query & return the results. I keep getting {"code":143,"error":"Invalid webhook response status: 500 Internal Server Error"} as the response.

I'm fairly certain it is not my code that is the problem and am guessing there is some configuration step or something I'm missing.

Here is my modified Parse function:

// Hello
Parse.Cloud.define('hello', function(request, response) {    
  var query = Parse.Query("Favorites");

  query.find({ useMasterKey: true }).then(
    function(results) {
      response.success('win');
    }, function() {
      response.error('fail');
    });

});

And a picture of my Parse Class with the inserted row:

I have Googled the error and can't find any good answers only poorly worded questions. I'm completely at a loss here. Thanks in advance for your help.


回答1:


Looks like Parse is wrong initialised on register-webhooks.js post deploy script: Parse.initialize(process.env.PARSE_APP_ID, "unused", process.env.PARSE_MASTER_KEY);

And without second parameter (JavaScript Key) you can't execute any Parse.Query from cloud functions.

So my solution is:

  1. Add new PARSE_JS_KEY to Heroku Config Variables (value is JavaScript Key from Parse->Settings->Keys)

  2. In server.js file add line:

    Parse.initialize(process.env.PARSE_APP_ID, process.env.PARSE_JS_KEY, process.env.PARSE_MASTER_KEY);

before require('./cloud/main.js');

PS: Place process.env.PARSE_JS_KEY directly in register-webhooks.js initializer does not work.



来源:https://stackoverflow.com/questions/33458741/parse-heroku-query-500-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!