1234567891011121314151617181920212223 |
- """
- 注册路由
- """
- from starlette.middleware.sessions import SessionMiddleware
- from fastapi.middleware.cors import CORSMiddleware
- from fastapi import FastAPI, Depends
- from api.api import router as api_router
- from api.token.v1 import login_required, router as key_router
- app = FastAPI()
- app.add_middleware(SessionMiddleware, secret_key='casper.com@2021')
- app.include_router(key_router)
- app.include_router(api_router, dependencies=[Depends(login_required)],
- responses={404: {'description': 'Not found!'}})
- # --- 支持跨域访问 --- see: https://blog.csdn.net/qq_33801641/article/details/120540963
- app.add_middleware(
- CORSMiddleware,
- allow_origins=["*"], # 允许访问的源
- allow_credentials=True, # 支持 cookie
- allow_methods=["*"], # 允许使用的请求方法
- allow_headers=["*"], # 允许携带的 Headers
- )
|