项目初次搭建

This commit is contained in:
2025-02-13 16:29:28 +08:00
parent feef37cbd7
commit 3cb2a4c507
121 changed files with 19550 additions and 0 deletions

View File

@ -0,0 +1,23 @@
from starlette.middleware.base import BaseHTTPMiddleware
from urllib.request import Request
from app.common.jwt_check import check_token
from app.common.logger_config import logger_http
class LoggerMiddleware(BaseHTTPMiddleware):
def __init__(self, app):
super().__init__(app)
async def dispatch(self, request: Request, call_next):
method = request.method
path = request.url.path
token = request.headers.get("Authorization")
user_id = None
if token:
decoded_payload = check_token(token)
user_id = decoded_payload['user_id']
logger_http.info(f"Path: {path},UserId: {user_id}, Method: {method}")
response = await call_next(request)
return response