Skip to content

Instantly share code, notes, and snippets.

@deangrant
Last active December 18, 2022 11:42
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 deangrant/6afbce5c9488ca9043dbc2fbb985e1fa to your computer and use it in GitHub Desktop.
Save deangrant/6afbce5c9488ca9043dbc2fbb985e1fa to your computer and use it in GitHub Desktop.
Initializes cross origin resource sharing for the application in Flask-Cors
CORS_ORIGINS=
CORS_METHODS=
CORS_ALLOW_HEADERS=
CORS_EXPOSE_HEADERS=
CORS_SUPPORTS_CREDENTIALS=
CORS_MAX_AGE=
# https://flask-cors.corydolphin.com/en/latest/api.html
CORS(
app=app,
resources = app.config['CORS_RESOURCES'],
origins = app.config['CORS_ORIGINS'],
methods = app.config['CORS_METHODS'],
allow_headers = app.config['CORS_ALLOW_HEADERS'],
expose_headers = app.config['CORS_EXPOSE_HEADERS'],
supports_credentials = app.config['CORS_SUPPORTS_CREDENTIALS'],
max_age = app.config['CORS_MAX_AGE']
)
@app.after_request
def after_request(response):
response.headers.add(
'Access-Control-Allow-Headers', app.config['CORS_ALLOW_HEADERS']
)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment