Skip to content
New issue

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

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

Already on GitHub? # to your account

Rest API Cross-origin resource sharing (CORS) #146

Closed
pvk-developer opened this issue May 31, 2019 · 0 comments · Fixed by #147
Closed

Rest API Cross-origin resource sharing (CORS) #146

pvk-developer opened this issue May 31, 2019 · 0 comments · Fixed by #147
Assignees
Milestone

Comments

@pvk-developer
Copy link
Member

  • ATM version: 0.2.0 / and previous
  • Python version: 3.6
  • Operating System: Ubuntu 18.04

Description

When you launch an ajax call to the REST API, you are getting blocked by CORS because there is a missing header.

What I Did

  • Create an dataset.
  • Launch the worker to populate the database.
  • Start an ATM API server.
  • Launch an ajax GET call to the API.

Then you are being blocked by CORS policy:

Access to XMLHttpRequest at 'http://127.0.0.1:5000/api/datasets/1' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Solution

In order to solve this problem, CORS headers for Access-Control-Allow-Origin and Access-Control-Allow-Credentials must be added to the response for each request:

    # Allow the CORS header
    @app.after_request
    def add_cors_headers(response):
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Credentials'] = 'true'
        return response
@pvk-developer pvk-developer self-assigned this Jun 10, 2019
@csala csala added this to the 0.2.1 milestone Jun 19, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants