add gzip & CORS middleware

This commit is contained in:
ducklet 2021-08-02 18:21:12 +02:00
parent b47dfc579b
commit c1b41d3882

View file

@ -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},
)