Skip to content

Instantly share code, notes, and snippets.

@hrisheekeshr
Created May 15, 2019 12:22
Show Gist options
  • Save hrisheekeshr/27bfac9d5936492799b3e64f417809ec to your computer and use it in GitHub Desktop.
Save hrisheekeshr/27bfac9d5936492799b3e64f417809ec to your computer and use it in GitHub Desktop.
Add CORS flask
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