Help us understand the problem. What is going on with this article?

Falcon CORS

More than 3 years have passed since last update.

Falcon CORS

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

https://pypi.python.org/pypi/falcon-cors

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"
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした