Last active
April 27, 2017 08:47
-
-
Save MOOOWOOO/cf91e02080740f2f17ab9d4d79825902 to your computer and use it in GitHub Desktop.
python decorator of cors
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 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