I'm trying to run parse-server locally by doing "npm start". I know that the server is running at http://localhost:1337, and when I enter this in the browser I get a valid response. However, when I try to connect to it using the Javascript API, I get this error:
POST http://localhost:1337/parse/login 403 (Forbidden)
It works if I host the backend on Heroku, which makes me think that the problem is that Parse in Javascript looks for an https link. This is how I load parse in Javascript:
var Parse = require('parse')
Parse.initialize('appID', 'javascriptKey')
Parse.serverURL = 'http://localhost:1337/parse'
Most of the solutions involve adding "X-Parse-Application-Id" and "X-Parse-Master-Key" headers to the browser request, but the request is made through the Javascript API.
How can I work around this?
The 403 you're getting is the normal response for an unauthorized request. In this case, you would need to properly pass the headers necessary by your setup to authenticate via. A good example can be seen in the docs rest guide.
# Signup a new user
curl -X POST \
-H "X-Parse-Application-Id: app-id-here" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "X-Parse-Revocable-Session: 1" \
-H "Content-Type: application/json" \
-d '{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}' \
http://localhost:1337/parse/users
# Login as user
curl -X GET \
-H "X-Parse-Application-Id: app-id-here" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "X-Parse-Revocable-Session: 1" \
-G \
--data-urlencode 'username=cooldude6' \
--data-urlencode 'password=p_n7!-e8' \
http://localhost:1337/parse/login
Notice the appId and restKey being passed in the headers, if these are correct (and if the server is setup to require a REST key) you would get a different 400 response.
{"code":200,"error":"username/email is required."}
This was just pulled from the docs so I would recommend you get started there. Additionally we have some handy JS docs too.