Skip to content

Instantly share code, notes, and snippets.

@giwa
Last active May 27, 2016 14:16
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 giwa/b54c4e7cfee8b21bc41584f5e4a4463a to your computer and use it in GitHub Desktop.
Save giwa/b54c4e7cfee8b21bc41584f5e4a4463a to your computer and use it in GitHub Desktop.
import falcon
class CORSMiddleware:
def process_request(self, req, resp):
resp.set_header('Access-Control-Allow-Origin', '*')
class Todo:
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.body = '{"foo":"bar"}'
api = application = falcon.API(middleware=[CORSMiddleware()])
todo = Todo()
api.add_route('/todo', todo)
HTTP/1.1 200 OK
Connection: close
Date: Fri, 27 May 2016 07:14:46 GMT
Server: gunicorn/19.6.0
access-control-allow-origin: *
content-length: 13
content-type: application/json; charset=UTF-8
{
"foo": "bar"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment