Date

I run my Angular JS frontend on a different domain than my Falcon backend. When I tried to connect the two, chrome gave an XHR error: No 'Access-Control-Allow-Origin'. This lead me to Falcon's github issue 223 which is marked as open. Sebasmagri was kind enough to post a middleware fix, but his answer required a bit of editing to work. The code below work for me.

import falcon
import requests

ALLOWED_ORIGINS = ['http://localhost:8000'] # Or load this from a config file

class CorsMiddleware(object):

    def process_request(self, request, response):
        origin = request.get_header('Origin')
        if origin in ALLOWED_ORIGINS:
            response.set_header('Access-Control-Allow-Origin', origin)

api = application = falcon.API(middleware=[CorsMiddleware()]);