Skip to content

Instantly share code, notes, and snippets.

@fabiocerqueira
Last active December 11, 2016 23:24
Show Gist options
  • Save fabiocerqueira/304de594fe56094ea252868db8021144 to your computer and use it in GitHub Desktop.
Save fabiocerqueira/304de594fe56094ea252868db8021144 to your computer and use it in GitHub Desktop.
Simple CORS with Bottle
from bottle import Bottle, response
app = Bottle()
@app.hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
@app.route('/', method = 'OPTIONS')
@app.route('/<path:path>', method = 'OPTIONS')
def options_handler(path = None):
return
@app.post('/login')
def login():
return "logged"
if __name__ == '__main__':
app.run(host='localhost', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment