uvicorn logging instead middleware

This commit is contained in:
2025-09-28 16:50:49 +03:00
parent 71116de157
commit e18e16bde2
2 changed files with 17 additions and 10 deletions

View File

@@ -28,15 +28,15 @@ api.add_middleware(
allow_headers=headers,
)
@api.middleware("http") #Логирование заходов перед всеми endpoints
async def log_requests(request: Request, call_next):
ip = request.client.host #ip
ua = request.headers.get("user-agent") #browser
method = request.method #method
url = str(request.url) #url
print(f"[{method}] {url} from {ip} ({ua})")
response = await call_next(request)
return response
# @api.middleware("http") #Логирование заходов перед всеми endpoints / возможно не нужен, так как то же самое делает uvicorn
# async def log_requests(request: Request, call_next):
# ip = request.client.host #ip
# ua = request.headers.get("user-agent") #browser
# method = request.method #method
# url = str(request.url) #url
# print(f"[{method}] {url} from {ip} ({ua})")
# response = await call_next(request)
# return response
@api.get("/protected") #test
async def protected(current_user: str = Depends(JWT.current_user)):