from contextlib import asynccontextmanager from pathlib import Path # import uvicorn from fastapi import FastAPI from src.web.protected_routes.auth_routes import router as protected_router from src.web.protected_routes.protected_user_action_routes import ( router as protected_user_action_routes, ) @asynccontextmanager async def lifespan(app: FastAPI): create_dirs() yield print("shutting down") app=FastAPI(root_path="/", lifespan=lifespan) app.include_router(router=protected_router) app.include_router(router=protected_user_action_routes) @app.get("") async def root()->dict: return {"root":"hello, this is root"} def create_dirs(): dirs_to_create=("./DB", "./uploads/upload", "./uploads/upload_bad", "./uploads/upload_finished") for x in dirs_to_create: Path(x).mkdir(parents=True, exist_ok=True)