Parse-server cloud code function 'Cannot POST'

放肆的年华 提交于 2019-12-12 08:46:13

问题


Most parts of my migration to open source parse-server are successful, with my data correctly stored, accessible.

I am however having problems with cloud code, specifically with running simple curl tests.

The initial parse-server installation includes a sample main.js file that contains a hello world function

My own parse installation is hosted at '/parse' so URLs use this as the root

The following is a simple request test

 curl -X POST \   
 -H "X-Parse-Application-Id: myAppId" \   
 -H "X-Parse-REST-API-Key:myRESTKey" \   
 -H "Content-Type: application/json" \   
 -d '{}' \  
 http://localhost:1337/parse/1/functions/hello

The response I get is

Cannot POST /parse/1/functions/hello

Which I take to be curls perfunctory statement that it cannot find a suitable POST endpoint

What is going wrong here? I have simply changed the sample curl example from Parse.com's documentation on using cloud-code to use my parse-server installation details


回答1:


The answer is that unlike with Parses hosted solution the API version path is not something hosted with parse-server

if you host parse at e.g.: /parse as I have done above, then that is the relative URL where the functions API is available. So simply remove the /1/ from the path

The same curl command works with this URL

http://localhost:1337/parse/functions/hello

eg:

curl -X POST \   
-H "X-Parse-Application-Id: myAppId" \   
-H "X-Parse-REST-API-Key:myRESTKey" \   
-H "Content-Type: application/json" \   
-d '{}' \  
http://localhost:1337/parse/functions/hello



回答2:


I applied the "hello post" logic below to run a function that is defined in Parse Open Source cloud code in main.js hosted on heroku. I am trying to replace a former job that ran on parse.com. Started with Curl to try and be able to run function at will.

error: Cannot GET /parse/functions/sendOutboundProgressReport STATE: PERFORM => DONE handle 0x6000578c0; line 1981 (connection #2) multi_done Curl_http_done: called premature ==0 Connection #2 to host test-fake-app.herokuapp.com left intact Expire cleared


curl -v POST \

-H 'X-Parse-Application-Id: sadf435hsdgfatea' \ -H 'X-Parse-Master-Key: asdfsaasdfae4235dsgd' \ -H 'REST_KEY': asdfasq435636 \ -H "Content-Type: application/json" \ -H "X-Parse-Url: http://test-fake-app.herokuapp.com/parse" \

-d @send-template.json \

http://test-fake-app.herokuapp.com/parse/functions/sendOutboundProgressReport



来源:https://stackoverflow.com/questions/35504293/parse-server-cloud-code-function-cannot-post

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