From c1b41d3882a8d74702d8e0f5c2488f47a028c73a Mon Sep 17 00:00:00 2001 From: ducklet Date: Mon, 2 Aug 2021 18:21:12 +0200 Subject: [PATCH] add gzip & CORS middleware --- unwind/web.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/unwind/web.py b/unwind/web.py index f2bb103..c5edbd4 100644 --- a/unwind/web.py +++ b/unwind/web.py @@ -17,6 +17,8 @@ from starlette.background import BackgroundTask from starlette.exceptions import HTTPException from starlette.middleware import Middleware from starlette.middleware.authentication import AuthenticationMiddleware +from starlette.middleware.cors import CORSMiddleware +from starlette.middleware.gzip import GZipMiddleware from starlette.responses import JSONResponse from starlette.routing import Mount, Route @@ -391,6 +393,17 @@ def create_app(): backend=BearerAuthBackend(config.api_credentials), on_error=auth_error, ), + Middleware( + CORSMiddleware, + allow_origins=[ + # "*", + "http://localhost:3000", + ], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ), + Middleware(GZipMiddleware), ], exception_handlers={HTTPException: http_exception}, )