Utilizing Other Advanced Features
296
To resolve
this issue, we need our
main.py
module to place all the origins
of our application
and other integrated resources used by the prototype inside a
List
. Then,
we import the built-in
CORSMiddleware
from the
fastapi.middleware.cors
module and add that to the
FastAPI
constructor with the list of origins, which should not be too
long to avoid overhead from
validating each URL. The following code snippet shows the injection of
CORSMiddleware
into
the
FastAPI
constructor:
origins = [
"https://192.168.10.2",
"http://192.168.10.2",
"https://localhost:8080",
"http://localhost:8080"
]
app = FastAPI(middleware=[
Middleware(SessionMiddleware,
secret_key
=
'7UzGQS7woBazLUtVQJG39ywOP7J7lkPkB0UmDhMgBR8=',
session_cookie="session_vars"),
Middleware(SessionDbMiddleware,
sess_key
=
'7UzGQS7woBazLUtVQJG39ywOP7J7lkPkB0UmDhMgBR8=',
sess_name='session_db', expiry='2020-10-10')
])
Chia sẻ với bạn bè của bạn: