def get_application() -> FastAPI: settings = get_settings() application = FastAPI( title=settings.APP_NAME, debug=settings.DEBUG, ) application.add_middleware( CORSMiddleware, allow_origins=settings.ALLOWED_HOSTS or ["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) application.include_router( router, prefix=settings.API_PREFIX, ) return application
User, Token, UserModel, UserIn, UserPassword, ) from app.services.users import ( get_user, authenticate_user, create_access_token, create_user, update_password, ) user_route = APIRouter() settings = get_settings() oauth2_scheme = OAuth2PasswordBearer(tokenUrl=f"{settings.API_PREFIX}/login") async def get_current_user( db: Session = Depends(get_db), token: str = Depends(oauth2_scheme), ): credentials_exception = HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Could not validate credentials", headers={"WWW-Authenticate": "Bearer"}, ) try: payload = jwt.decode(token,
from app.config.settings import Settings, get_settings import logging from app.config.db import init_db from fastapi import FastAPI from app.api import ping, users log = logging.getLogger(__name__) settings: Settings = get_settings() def create_application() -> FastAPI: app = FastAPI(title=settings.APP_NAME) app.include_router(ping.router) app.include_router(users.router, prefix='/users', tags=['Users']) return app app = create_application() @app.on_event('startup') async def startup_event(): log.info('Starting up...') init_db(app) @app.on_event('shutdown') async def shutdown_event():