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

Add Access-Control-Allow-Origin: * to JSON responses for anonymous search requests #2186

Closed
hubgit opened this issue Apr 22, 2015 · 7 comments

Comments

@hubgit
Copy link

hubgit commented Apr 22, 2015

I'd like to be able to search the API for annotations of the current page, in client-side Javascript.

Currently there's no Access-Control-Allow-Origin: * header on the JSON response, so it's not possible to call the API from a different domain (unlike via.hypothes.is, which is able to call the API as it's on the same domain).

As the search results are sometimes filtered according to the current user, and the Access-Control-Allow-Origin: * prevents the response to authenticated requests being read, the header should only be added to anonymous requests (meaning that only non-authenticated requests would be readable cross-domain).

I think it needs to be added somewhere around https://github.com/hypothesis/h/blob/master/h/api/views.py#L77

@judell
Copy link
Contributor

judell commented Apr 22, 2015

Thanks Alf, good call, we like this.

@wagoodman
Copy link

I believe you need request.response.headers["Access-Control-Allow-Origin"] = "*"
before the return statement.

@tilgovi
Copy link
Contributor

tilgovi commented Apr 24, 2015

We also need to support the OPTIONS request. This is probably best handled with a view decorator or a tween.

@BigBlueHat
Copy link
Contributor

@hubgit @wagoodman rather than wait for us to get this through our queue, I'd recommend setting up a CORS proxy to handle requests to the Hypothes.is API.

corsproxy is a good one if you're running Node.js.

You could also test with these plubic CORS proxy (though YMMV):
https://jsonp.afeld.me/
http://cors.maxogden.com/

Hopefully that'll let you keep hacking while you wait on us. 😸

@tilgovi
Copy link
Contributor

tilgovi commented May 4, 2015

Or make a pull request :-D

@BigBlueHat
Copy link
Contributor

Oh right! or that. 😉

@hubgit
Copy link
Author

hubgit commented May 5, 2015

We also need to support the OPTIONS request.

I don't think it's necessary to support OPTIONS for GET requests.

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

5 participants