app.py 863 B

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