6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Falcon CORS

Last updated at Posted at 2016-05-27

Falcon CORS

There is a package for cors. But we can add CORS function very easily.

Use middleware and attach acess-control-allow-origin


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"
}
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?