diff --git a/.env.example b/.env.example index 704d0a8a..91155d64 100644 --- a/.env.example +++ b/.env.example @@ -61,6 +61,9 @@ PROXY_USE_IPV4=true # ⏱️ 请求超时配置 REQUEST_TIMEOUT=600000 # 请求超时设置(毫秒),默认10分钟 +# 🔧 请求体大小配置 +REQUEST_MAX_SIZE_MB=60 + # 📈 使用限制 DEFAULT_TOKEN_LIMIT=1000000 diff --git a/docker-compose.yml b/docker-compose.yml index 79b9afb8..d8f78a24 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,9 @@ services: - PORT=3000 - HOST=0.0.0.0 + # 🔧 请求体大小配置 + - REQUEST_MAX_SIZE_MB=60 + # 🔐 安全配置(必填) - JWT_SECRET=${JWT_SECRET} # 必填:至少32字符的随机字符串 - ENCRYPTION_KEY=${ENCRYPTION_KEY} # 必填:32字符的加密密钥 diff --git a/src/middleware/auth.js b/src/middleware/auth.js index a5568323..e5a449b6 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1388,7 +1388,8 @@ const globalRateLimit = async (req, res, next) => // 📊 请求大小限制中间件 const requestSizeLimit = (req, res, next) => { - const maxSize = 60 * 1024 * 1024 // 60MB + const MAX_SIZE_MB = parseInt(process.env.REQUEST_MAX_SIZE_MB || '60', 10) + const maxSize = MAX_SIZE_MB * 1024 * 1024 const contentLength = parseInt(req.headers['content-length'] || '0') if (contentLength > maxSize) {