refactor: 配置安全加固-从TOML移除密钥+去除死代码+统一端口

P0: 从config/production.toml和config/development.toml移除wechat_secret/jwt_secret
    这些密钥现在仅通过.env(EnvironmentFile)加载,不再进入Git历史
    config.rs: 新增直接环境变量名回退(JWT_SECRET而非仅APP_JWT_SECRET)
    
P1: - 移除config.rs中的server_ports字段(死代码,未被任何代码使用)
    - 简化main.rs端口fallback: 生产环境仅4433,开发环境仅8080/3000
    - .env.example版本号0.2.3→0.3.0
    
Docs: - AGENTS.md测试域名xmclassmate.top/dev→dev.xmclassmate.top
This commit is contained in:
moira
2026-05-13 15:17:45 +08:00
parent d879b65662
commit bded0113ee
6 changed files with 11 additions and 18 deletions

View File

@@ -17,8 +17,6 @@ pub struct AppConfig {
pub environment: String,
pub free_user_data_limit: i32,
pub server_host: String,
#[serde(rename = "server_ports")]
pub server_ports: Vec<u16>,
}
impl AppConfig {
@@ -57,16 +55,17 @@ impl AppConfig {
}
// 3. 从环境变量加载(最高优先级)
// 支持两种前缀APP_*(推荐)和直接变量名(兼容 systemd EnvironmentFile
if let Ok(val) = std::env::var("APP_DATABASE_URL") {
settings.insert("database_url".into(), toml::Value::String(val));
}
if let Ok(val) = std::env::var("APP_JWT_SECRET") {
if let Ok(val) = std::env::var("APP_JWT_SECRET").or_else(|_| std::env::var("JWT_SECRET")) {
settings.insert("jwt_secret".into(), toml::Value::String(val));
}
if let Ok(val) = std::env::var("APP_WECHAT_APPID") {
if let Ok(val) = std::env::var("APP_WECHAT_APPID").or_else(|_| std::env::var("WECHAT_APPID")) {
settings.insert("wechat_appid".into(), toml::Value::String(val));
}
if let Ok(val) = std::env::var("APP_WECHAT_SECRET") {
if let Ok(val) = std::env::var("APP_WECHAT_SECRET").or_else(|_| std::env::var("WECHAT_SECRET")) {
settings.insert("wechat_secret".into(), toml::Value::String(val));
}
if let Ok(val) = std::env::var("APP_RUST_LOG") {

View File

@@ -183,10 +183,10 @@ async fn main() -> std::io::Result<()> {
info!("Attempting to start server...");
let is_production = std::env::var("APP_ENV").unwrap_or_else(|_| "development".into()) == "production";
let ports = if is_production {
vec![4433, 8443, 8080, 3000, 8000, 8888]
let ports: Vec<u16> = if is_production {
vec![4433]
} else {
vec![8080, 3000, 8000, 8888, 4433, 8443]
vec![8080, 3000]
};
let mut server: Option<
Pin<Box<dyn std::future::Future<Output = std::io::Result<()>> + Unpin>>,