短信发送失败增加冷却防连点限流并配置trust proxy恢复真实客户端IP
This commit is contained in:
@@ -44,6 +44,13 @@ export function validateRuntimeConfig(
|
||||
const productionLike = isProductionLike(env)
|
||||
|
||||
requireInteger(issues, 'server.port', config.server?.port, { min: 1, max: 65535 })
|
||||
const trustProxy = config.server?.trustProxy
|
||||
if (trustProxy !== undefined && trustProxy !== null && !isValidTrustProxy(trustProxy)) {
|
||||
issues.push({
|
||||
path: 'server.trustProxy',
|
||||
message: 'server.trustProxy 仅支持 true/false、非负整数或 loopback/uniquelocal/linklocal',
|
||||
})
|
||||
}
|
||||
requireInteger(issues, 'database.maxConnections', config.database?.maxConnections, { min: 1 })
|
||||
requireOptionalInteger(issues, 'database.idleTimeoutMs', config.database?.idleTimeoutMs, {
|
||||
min: 1,
|
||||
@@ -288,6 +295,12 @@ function requireOptionalInteger(
|
||||
requireInteger(issues, configPath, value, options)
|
||||
}
|
||||
|
||||
function isValidTrustProxy(value: unknown): boolean {
|
||||
if (typeof value === 'boolean') return true
|
||||
if (typeof value === 'number') return Number.isInteger(value) && value >= 0
|
||||
return ['loopback', 'uniquelocal', 'linklocal'].includes(String(value))
|
||||
}
|
||||
|
||||
function isHttpUrl(value: string): boolean {
|
||||
try {
|
||||
const url = new URL(value)
|
||||
|
||||
Reference in New Issue
Block a user