feat: KKS P240/P241 蓝牙工牌管理系统初始提交
FastAPI + SQLAlchemy + asyncio TCP 服务器,支持设备管理、实时定位、 告警、考勤打卡、蓝牙记录、指令下发、TTS语音播报等功能。
This commit is contained in:
22
app/extensions.py
Normal file
22
app/extensions.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
Shared extension instances (rate limiter, etc.) to avoid circular imports.
|
||||
"""
|
||||
|
||||
from starlette.requests import Request
|
||||
from slowapi import Limiter
|
||||
|
||||
from app.config import settings
|
||||
|
||||
|
||||
def _get_real_client_ip(request: Request) -> str:
|
||||
"""Extract real client IP from X-Forwarded-For (behind Cloudflare/nginx) or fallback."""
|
||||
forwarded = request.headers.get("X-Forwarded-For")
|
||||
if forwarded:
|
||||
return forwarded.split(",")[0].strip()
|
||||
cf_ip = request.headers.get("CF-Connecting-IP")
|
||||
if cf_ip:
|
||||
return cf_ip.strip()
|
||||
return request.client.host if request.client else "127.0.0.1"
|
||||
|
||||
|
||||
limiter = Limiter(key_func=_get_real_client_ip, default_limits=[settings.RATE_LIMIT_DEFAULT])
|
||||
Reference in New Issue
Block a user