Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 10, 2020 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/dcdace089ed46e56968928bc28c34947 to your computer and use it in GitHub Desktop.
Save parzibyte/dcdace089ed46e56968928bc28c34947 to your computer and use it in GitHub Desktop.
"""
Enable CORS. Disable it if you don't need CORS
https://parzibyte.me/blog
"""
@app.after_request
def after_request(response):
response.headers["Access-Control-Allow-Origin"] = "*" # <- You can change "*" for a domain for example "http://localhost"
response.headers["Access-Control-Allow-Credentials"] = "true"
response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PUT, DELETE"
response.headers["Access-Control-Allow-Headers"] = "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization"
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment