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

Address CORS issues with Open Library API endpoints #329

Closed
danielancines opened this issue Oct 4, 2016 · 12 comments
Closed

Address CORS issues with Open Library API endpoints #329

danielancines opened this issue Oct 4, 2016 · 12 comments

Comments

@danielancines
Copy link

danielancines commented Oct 4, 2016

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?

#220

https://plnkr.co/edit/OPc95v?p=preview

Thanks.

@bfalling bfalling changed the title Cors issues at http://openlibrary.org/api/books?bibkeys=ISBN:0201558025&jscmd=data Address CORS issues with Open Library API endpoints Oct 4, 2016
@bfalling
Copy link
Collaborator

bfalling commented Oct 4, 2016

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.

@ahstro
Copy link

ahstro commented Sep 27, 2017

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?

@mekarpeles
Copy link
Member

Can investigate

@ahstro
Copy link

ahstro commented Sep 28, 2017

That would be very much appreciated! ☺️

@mekarpeles
Copy link
Member

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:
90f8990
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";
}

@mekarpeles
Copy link
Member

@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)

@mekarpeles
Copy link
Member

Please continue to open bugs as specific json endpoints are needed and we can make this prescribed change.

@mekarpeles
Copy link
Member

Closing -- please re-open with a specific endpoint which requires enabling cors, or if #570 did not resolve the issue

@ahstro
Copy link

ahstro commented Sep 29, 2017

Think you forgot to close 😉 Also, thanks! 🙌

@kaaniboy
Copy link

Unfortunately, it seems like the CORS issue still persists for the Covers API. Is there any way this endpoint can be adjusted as well?

@brijeshpthankachan
Copy link

still giving cors error when trying to access the following api (angular)

    this.http.get(`https://openlibrary.org/isbn/9780385513227
    `).subscribe(e => {
      next: (res: any) => console.log(res)
    })

@Sara-pixie
Copy link

Also an issue with https://openlibrary.org/search.json APIs

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

7 participants