Skip to content

nmcbride/falcon-cors

 
 

Repository files navigation

https://travis-ci.org/lwcolton/falcon-cors.svg?branch=master

falcon-cors

About

This is a CORS algorithm and a falcon middleware for CORS.

Interface Documentation: https://falcon-cors.readthedocs.org/en/master/falcon_cors.html

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

Install

pip install falcon-cors

Usage

import falcon
from falcon_cors import CORS

cors = CORS(allow_origins_list=['http://test.com:8080'])

api = falcon.API(middleware=[cors.middleware])

Override CORS for a specific resource

import falcon
from falcon_cors import CORS

cors = CORS(allow_origins_list=['http://test.com:8080'])

api = falcon.API(middleware=[cors.middleware])

public_cors = CORS(allow_all_origins=True)

class MyPublicResource:
    cors = public_cors

    def on_post(self, req, resp):
        resp.body = "Everone can post to this resource"

api.add_route("/public", MyPublicResource())

Turn CORS off for a specific resource

class MyResource:
    cors_enabled = False

Tests and Contributing

If you want to contribute just submit a PR and please make sure you have created some tests for your feature.

Packages

No packages published

Languages

  • Python 98.4%
  • Shell 1.6%