app.py 879 B

123456789101112131415161718192021222324
  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 key.v1 import router as token_router
  8. from key.v1 import login_required
  9. from api.api import router as api_router
  10. app = FastAPI()
  11. app.add_middleware(SessionMiddleware, secret_key='casper.com@2021')
  12. app.include_router(token_router)
  13. app.include_router(api_router, dependencies=[Depends(login_required)],
  14. responses={404: {'description': 'Not found!'}})
  15. # --- 支持跨域访问 --- see: https://blog.csdn.net/qq_33801641/article/details/120540963
  16. app.add_middleware(
  17. CORSMiddleware,
  18. allow_origins=["*"], # 允许访问的源
  19. allow_credentials=True, # 支持 cookie
  20. allow_methods=["*"], # 允许使用的请求方法
  21. allow_headers=["*"], # 允许携带的 Headers
  22. )