Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Last active April 27, 2017 08:47
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 MOOOWOOO/cf91e02080740f2f17ab9d4d79825902 to your computer and use it in GitHub Desktop.
Save MOOOWOOO/cf91e02080740f2f17ab9d4d79825902 to your computer and use it in GitHub Desktop.
python decorator of cors
def cors(func):
@wraps(func)
def wrapper_func(*args, **kwargs):
r = make_response(func(*args, **kwargs))
# list your access domain here
# if set 'Access-Control-Allow-Credentials', this cannot be *.
# must match the require domain
r.headers['Access-Control-Allow-Origin'] = '*'
r.headers['Access-Contorl-Allow-Methods'] = 'GET, POST, PUT, DELETE' # list your access methods here
allow_headers = "Referer, Accept, Origin, User-Agent"
r.headers['Access-Control-Allow-Headers'] = allow_headers
# if you need the cookie access, uncomment this line
# r.headers['Access-Control-Allow-Credentials'] = True
return r
return wrapper_func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment