Skip to content

ParseFile upload with javasctipt creating Access-Control-Allow-Origin #118

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

Closed
skavinvarnan opened this issue Feb 1, 2016 · 5 comments
Closed

Comments

@skavinvarnan
Copy link

When i tried to upload a file to parse-server using this documentation its throwing an error Access-Control-Allow-Origin.

Digging more into the request and response i found that the below Response Header is missing out these
Access-Control-Allow-Headers:*
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin:*

I tried saving a ParseObject using this documentation In that response i do get the above Response Headers and everything works fine

Note: I tried to upload the ParseFile with the same code to Parse Main server and everything worked fine. I also got the Response Header as * for Access-Control-Allow-Headers and Methods

I found a comment in files.js
// TODO: do we need to allow crossdomain and method override?

I think my problem will be solved when crossdomain is added

Environment:
node version: 4.2.4
parse-server version: 2.0.3

@samarthagarwal
Copy link

I solved it by using the following.

app.use(function(mountPath, res, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    return next();
  });

@skavinvarnan
Copy link
Author

@samarthagarwal
Nice work.

But this can be used as a temporary solution. The exact solution would be adding a middleware Response Header in the files.js itself.

I tried to give a solution but unable to understand the flow.
But well aware that middleware.js crossdomain should be added to files.js in this route

@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

@skavinvarnan Would you like to submit a PR?

@vbabaria
Copy link

@samarthagarwal - Could you pls suggest file name and location to enable CORS with above fix? not sure where exactly i need to apply fix on parse-server

thank you

@gfosco
Copy link
Contributor

gfosco commented Feb 20, 2016

This should be working in #390 and will be in 2.1.3 (or you can pull master.) Please open a new issue if you still have problems. Thanks.

@gfosco gfosco closed this as completed Feb 20, 2016
bernhardharrer pushed a commit to bernhardharrer/parse-server that referenced this issue Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants