feat(api): added rate limiting
- Need update on testing env
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/control", tags=["control"])
|
||||
router = APIRouter(
|
||||
prefix="/control",
|
||||
tags=["control"],
|
||||
)
|
||||
|
||||
|
||||
@router.get("/ping")
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import redis.asyncio as redis
|
||||
from fastapi import FastAPI
|
||||
from fastapi_limiter import FastAPILimiter
|
||||
|
||||
from src.neo_neo_todo.control import control
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
redis_connection = redis.from_url("redis://localhost:6379", encoding="utf8")
|
||||
await FastAPILimiter.init(redis_connection)
|
||||
yield
|
||||
await FastAPILimiter.close()
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
app.include_router(control.router)
|
||||
|
||||
Reference in New Issue
Block a user