feat(server): 限流 fail-close 统一配置
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 新增 RateLimitConfig 结构体,支持 config.toml + 环境变量
- apply_rate_limit 统一读取 fail_close 配置,生产环境可设为拒绝请求
- account_lockout_middleware 改为从 AppState.config 读取,不再直接读环境变量
- default.toml 添加 [rate_limit] 配置节
This commit is contained in:
iven
2026-05-03 09:46:02 +08:00
parent 1a6409eb30
commit 209acaa15d
3 changed files with 53 additions and 11 deletions

View File

@@ -14,6 +14,8 @@ pub struct AppConfig {
pub crypto: CryptoConfig,
pub ai: AiConfig,
pub storage: StorageConfig,
#[serde(default)]
pub rate_limit: RateLimitConfig,
}
#[derive(Debug, Clone, Deserialize)]
@@ -123,6 +125,19 @@ impl StorageConfig {
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct RateLimitConfig {
/// Redis 不可达时是否拒绝请求(生产环境必须为 true
#[serde(default)]
pub fail_close: bool,
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self { fail_close: false }
}
}
impl AppConfig {
pub fn load() -> anyhow::Result<Self> {
let config = config::Config::builder()