Refactor: Modularize middleware and router registration in app/main.py
This commit is contained in:
12
app/middleware.py
Normal file
12
app/middleware.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import time
|
||||
from fastapi import Request
|
||||
|
||||
async def add_process_time_header(request: Request, call_next):
|
||||
"""
|
||||
Middleware to add the processing time to the response header.
|
||||
"""
|
||||
start_time = time.time()
|
||||
response = await call_next(request)
|
||||
process_time = time.time() - start_time
|
||||
response.headers['X-Process-Time'] = str(process_time)
|
||||
return response
|
||||
Reference in New Issue
Block a user