mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
add auth and redis endpoints
This commit is contained in:
31
app/main.py
31
app/main.py
@@ -1,24 +1,35 @@
|
||||
from fastapi import FastAPI
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, Depends
|
||||
|
||||
from app.api.nonsense import router as nonsense_router
|
||||
from app.api.shakespeare import router as shakespeare_router
|
||||
from app.api.stuff import router as stuff_router
|
||||
from app.utils.logging import AppLogger
|
||||
from app.api.user import router as user_router
|
||||
from app.api.health import router as health_router
|
||||
from app.redis import get_redis
|
||||
from app.services.auth import AuthBearer
|
||||
|
||||
logger = AppLogger.__call__().get_logger()
|
||||
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.5")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Load the redis connection
|
||||
app.state.redis = await get_redis()
|
||||
yield
|
||||
# close redis connection and release the resources
|
||||
app.state.redis.close()
|
||||
|
||||
|
||||
app = FastAPI(title="Stuff And Nonsense API", version="0.6", lifespan=lifespan)
|
||||
|
||||
app.include_router(stuff_router)
|
||||
app.include_router(nonsense_router)
|
||||
app.include_router(shakespeare_router)
|
||||
app.include_router(user_router)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("Starting up...")
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
logger.info("Shutting down...")
|
||||
app.include_router(health_router, prefix="/v1/public/health", tags=["Health, Public"])
|
||||
app.include_router(health_router, prefix="/v1/health", tags=["Health, Bearer"], dependencies=[Depends(AuthBearer())])
|
||||
|
||||
Reference in New Issue
Block a user