Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request header field X-Parse-Application-ID is not allowed by Access-Control-Allow-Headers in preflight response. #53

Closed
VesperDev opened this issue Feb 11, 2016 · 7 comments
Labels

Comments

@VesperDev
Copy link

Hello such community I have the following question'm trying to upload a file, but I have the following error

captura

captura2

add these lines of code for testing file uploading #20
change the application ID and the rest-api-key
and finally add a service to upload the file

 Upload: function(file) {

    var defer = $q.defer();
    var parseFile = new Parse.File(file.name, file);

    parseFile.save({
      success: function(savedFile) {
        defer.resolve(savedFile);
      },
      error: function(error) {
        defer.reject(error);
      }
    });

    return defer.promise;

but it continues to appear the same mistake :(

MLHttpRequest cannot load https://xxxxxxxx/parse/files/4188biun0z82kklf3euc_400x400.jpeg. Request header field X-Parse-Application-ID is not allowed by Access-Control-Allow-Headers in preflight response.
main.js:43 Unable to connect to the Parse API

Anyone know how I solve this?

Thank you very much for your time

@drew-gross
Copy link
Contributor

Have you set the correct serverURL including parse mount point in your app? If so, then this sounds like a CORS issue that we should fix. In the meantime, the workaround would be to host your parse server and your website on the same domain (including subdomain). This is definitely not the ideal situation, though, so we will definitely seek to address this bug. You could also submit a PR :)

@VesperDev
Copy link
Author

hello @drew-gross replace the app-id and the rest-api-key

app.all('', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '
');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'accept, content-type,aa, bb, x-parse-session-token');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
}
});

aa = x-parse-application-id
bb = x-parse-rest-api-key

I make a small application to test that everything is working . the parse.initializate is this

Parse.initialize('cc','dd');
Parse.serverURL = 'https://urlheroku.com/parse';

cc = application_id
dd = javacript_key

all right even create a new document in mongodb no problem.
this detail when uploading a file.

I will be doing wrong?
thanks for you time.

@drew-gross
Copy link
Contributor

We'll do some additional investigation. In the meantime, if you could provide a complete reproduction script or test case that would be very helpful (ie. a parse-server application and JS application that we can run and instantly see the problem)

@asContagious
Copy link

I'm having this issue just trying to connect through the JS SDK:
ERR Connection refused:
{code: 100, message: "XMLHttpRequest failed: "Unable to connect to the Parse API""}

@vbabaria
Copy link

+1

got same error...

"XMLHttpRequest cannot load http://localhost:1337/parse/classes/Generic. Request header field X-Parse-Application-Id is not allowed by Access-Control-Allow-Headers in preflight response."

using below simple restful call fails connecting to parse-server and same code works via parse.com (commented out line below)

any help would be really appreciated - thanks

$.ajax({
type: "GET",
//url: "https://api.parse.com/1/classes/Generic", // works
url: "http://localhost:1337/parse/classes/Generic", // fails
data: "",
contentType: "application/json",
headers: {
"Content-Type": "application/json",
"X-Parse-Application-Id":"app key",
"X-Parse-REST-API-Key":"rest api key"
},
success: function(data){
console.log(data);
}
});

@vxb8874
Copy link

vxb8874 commented Feb 19, 2016

ran into same bug and can't find any solution - would really appreciate any pointers

@drew-gross
Copy link
Contributor

This issue is fixed in parse-community/parse-server#390 If you don't want to wait for the next release, you can clone the repo and run the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants