add gzip & CORS middleware
This commit is contained in:
parent
b47dfc579b
commit
c1b41d3882
1 changed files with 13 additions and 0 deletions
|
|
@ -17,6 +17,8 @@ from starlette.background import BackgroundTask
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
from starlette.middleware import Middleware
|
from starlette.middleware import Middleware
|
||||||
from starlette.middleware.authentication import AuthenticationMiddleware
|
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.responses import JSONResponse
|
||||||
from starlette.routing import Mount, Route
|
from starlette.routing import Mount, Route
|
||||||
|
|
||||||
|
|
@ -391,6 +393,17 @@ def create_app():
|
||||||
backend=BearerAuthBackend(config.api_credentials),
|
backend=BearerAuthBackend(config.api_credentials),
|
||||||
on_error=auth_error,
|
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},
|
exception_handlers={HTTPException: http_exception},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue