-
-
Save brianraila/515ca7028acaecbf4b7695867078185d to your computer and use it in GitHub Desktop.
How to add CORS support to a Flask app in 9 lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_cors_headers(response): | |
response.headers['Access-Control-Allow-Origin'] = '*' | |
if request.method == 'OPTIONS': | |
response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT' | |
headers = request.headers.get('Access-Control-Request-Headers') | |
if headers: | |
response.headers['Access-Control-Allow-Headers'] = headers | |
return response | |
app.after_request(add_cors_headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment