feat(config): 增加 IP 归属地查询开关

新增 IP_LOCATION_ENABLE 配置项,允许在生产环境中关闭登录时的第三方 IP 查询请求,并统一使用 HTTPX_DEFAULT_TIMEOUT 超时设置。
This commit is contained in:
zhangtao
2026-05-12 21:05:05 +08:00
parent 392ff49232
commit 5a9757e9de
5 changed files with 9 additions and 25 deletions
+1
View File
@@ -140,6 +140,7 @@ class Settings(BaseSettings):
# ******************* 外部 HTTPhttpx******************* # # ******************* 外部 HTTPhttpx******************* #
# ================================================= # # ================================================= #
HTTPX_DEFAULT_TIMEOUT: float = 10.0 # 对外请求默认超时(秒),见 app/common/httpx_defaults.py HTTPX_DEFAULT_TIMEOUT: float = 10.0 # 对外请求默认超时(秒),见 app/common/httpx_defaults.py
IP_LOCATION_ENABLE: bool = True # 是否启用 IP 归属地查询(登录时对外发起 HTTP 请求)
# ================================================= # # ================================================= #
# ********************* 日志配置 ******************* # # ********************* 日志配置 ******************* #
+2 -2
View File
@@ -57,7 +57,7 @@ class IpLocalUtil:
""" """
if not ip: if not ip:
return None return None
if settings.DEBUG: if settings.DEBUG or not settings.IP_LOCATION_ENABLE:
return ( return (
"内网IP" "内网IP"
if cls.is_private_ip(ip) if cls.is_private_ip(ip)
@@ -86,7 +86,7 @@ class IpLocalUtil:
return "内网IP" return "内网IP"
try: try:
async with httpx.AsyncClient(timeout=5) as client: async with httpx.AsyncClient(timeout=settings.HTTPX_DEFAULT_TIMEOUT) as client:
# 首选:ip9.com.cn API # 首选:ip9.com.cn API
url = f"https://ip9.com.cn/get?ip={ip}" url = f"https://ip9.com.cn/get?ip={ip}"
response = await cls._make_api_request(client, url) response = await cls._make_api_request(client, url)
+3
View File
@@ -47,3 +47,6 @@ LOGGER_LEVEL = "DEBUG" # 日志级别
OPENAI_BASE_URL = "https://api.deepseek.com" OPENAI_BASE_URL = "https://api.deepseek.com"
OPENAI_API_KEY = "your_api_key" OPENAI_API_KEY = "your_api_key"
OPENAI_MODEL = "deepseek-chat" OPENAI_MODEL = "deepseek-chat"
# IP 归属地查询(登录时对外请求第三方 API,生产建议关闭)
IP_LOCATION_ENABLE=false
+3
View File
@@ -47,3 +47,6 @@ LOGGER_LEVEL = 'INFO'
OPENAI_BASE_URL = "https://api.deepseek.com" OPENAI_BASE_URL = "https://api.deepseek.com"
OPENAI_API_KEY = "your_api_key" OPENAI_API_KEY = "your_api_key"
OPENAI_MODEL = "deepseek-chat" OPENAI_MODEL = "deepseek-chat"
# IP 归属地查询(登录时对外请求第三方 API,生产建议关闭)
IP_LOCATION_ENABLE=false
-23
View File
@@ -1,23 +0,0 @@
# 数据库配置
MYSQL_ROOT_PASSWORD=your_mysql_root_password
MYSQL_DATABASE=fastapiadmin
MYSQL_USER=fastapiadmin
MYSQL_PASSWORD=your_mysql_password
MYSQL_PORT=3306
# Redis配置
REDIS_PASSWORD=your_redis_password
REDIS_PORT=6379
# 后端配置
BACKEND_PORT=8001
# Nginx配置
HTTP_PORT=80
HTTPS_PORT=443
# 项目配置
PROJECT_NAME=FastapiAdmin
# 部署环境 (dev/prod)
DEPLOY_ENV=prod