Skip to content

Instantly share code, notes, and snippets.

@mushfiq

mushfiq/cors.py

Last active Oct 7, 2015
Embed
What would you like to do?
python decorator for bottle framework to enable CORS to an endpoint.
from bottle import Bottle,response
def allow_cors(func):
""" this is a decorator which enable CORS for specified endpoint """
def wrapper(*args, **kwargs):
response.headers['Access-Control-Allow-Origin'] = 'example.com' # * in case you want to be accessed via any website
return func(*args, **kwargs)
return wrapper
#example usages in an API endpoint
app = Bottle()
@app.route("/endpoint/:id")
@allow_cors
def get_cakes_by_id():
# loading cakes by ID
return {"cakes": cakes}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.