Falcon (Python)
#Python #WEBフレームワーク #WSGI
The Falcon Web Framework — Falcon 3.0.1 documentation
高速
ミニマム
HTTPサーバーが組み込まれていないので、アプリケーションサーバーが必須
WSGI
テストモード
テストモードの場合、simple_serverを使用する。
ArgumentParser
引数の解析用
code:py
import falcon
from wsgiref import simple_server #テスト時に使用
from argparse import ArgumentParser
parser=ArgumentParser()
parser.add_argument('-t', '--test', action='store_true')
args = parser.parse_args()
application = falcon.API()
# テストモード
if args.test :
if __name__ == '__main__':
httpd = simple_server.make_server('127.0.0.1', 8080, application)
httpd.serve_forever()
CORSの設定
https://github.com/lwcolton/falcon-cors
falcon-corsを使用したが、falconで標準装備されていそう。
CORS — Falcon 3.0.1 documentation
code:python
from falcon_cors import CORS
cors = CORS(allow_origins_list=['http://localhost:8080'],allow_methods_list=['GET','POST'],allow_headers_list=['Origin','Authorization','Accept'],allow_credentials_all_origins=True)
application = falcon.API(middleware=cors.middleware)