I'm using angular $http feature to access the Open Library and I've got cors error
XMLHttpRequest cannot load http://openlibrary.org/api/books?bibkeys=ISBN:0201558025&jscmd=data. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.>
Looking for this at Google I found this link with this same error, are you'll look for this someday?
https://github.com/internetarchive/openlibrary/issues/220
https://plnkr.co/edit/OPc95v?p=preview
Thanks.
As noted in #220, of the various API's listed on https://openlibrary.org/dev/docs/api/, the search.json API is now open to cross-domain requests, but the others are not and should be addressed.
Still an issue. I don't really have any that much experience with server configs, but I could try to poke around and submit a PR unless someone could just fix it quickly?
Can investigate
That would be very much appreciated! 鈽猴笍
It looks like within openlibrary/openlibrary/plugins/openlibrary/processors.py there's a class CORSProcessor which is added within openlibrary/openlibrary/plugins/openlibrary/code.py as delegate.app.add_processor(processors.CORSProcessor())
In a previous commit, I see highlighted:
https://github.com/internetarchive/openlibrary/commit/90f899074d3d98d220a77d0ec1b7f4d70889ff71
if web.ctx.path.startswith("/api/") or web.ctx.path.endswith(".json"):
Which I can confirm is getting triggered via http://openlibrary.org/api/books?bibkeys=ISBN:0201558025&jscmd=data&format=json
nginx also seems to be behaving correctly
if ($uri ~ '\.json$') {
set $api_call "$scheme:api";
}
if ($uri ~ '^/api/.*$') {
set $api_call "$scheme:api";
}
@danielancines I believe I have this fixed for /api/books on our dev server. The endpoint will need to be called w/ .json.
https://dev.openlibrary.org/api/books.json?bibkeys=ISBN:0201558025&jscmd=data&format=json
The current endpoint books class in openlibrary/plugins/books/code.py does not extend delegate.page
Proposal is to add a route of the form:
class books_json(delegate.page):
path = "/api/books"
encoding = "json"
@jsonapi
def GET(self):
i = web.input(bibkeys='', callback=None, details="false")
i.format = "json"
return dynlinks.dynlinks(i.bibkeys.split(","), i)
Please continue to open bugs as specific json endpoints are needed and we can make this prescribed change.
Closing -- please re-open with a specific endpoint which requires enabling cors, or if #570 did not resolve the issue
Think you forgot to close 馃槈 Also, thanks! 馃檶
Unfortunately, it seems like the CORS issue still persists for the Covers API. Is there any way this endpoint can be adjusted as well?
Most helpful comment
As noted in #220, of the various API's listed on https://openlibrary.org/dev/docs/api/, the search.json API is now open to cross-domain requests, but the others are not and should be addressed.