From 62aa5b0e52859afe3ba9de1c7b11cfe2dacf6c2c Mon Sep 17 00:00:00 2001 From: mytheclipsebotreview Date: Thu, 30 Jul 2026 22:18:03 +0700 Subject: [PATCH] fix(config): remove list_separator, breaks string fields --- src/config/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 7e7b62b..62aac4d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -32,8 +32,8 @@ pub struct AppConfig { #[serde(default = "default_env")] pub environment: String, - /// Allowed CORS origins (comma-separated) - #[serde(default)] + /// Allowed CORS origins (comma-separated in env var, parsed to Vec) + #[serde(default, deserialize_with = "deserialize_comma_separated")] pub cors_origins: Vec, /// Log level (trace, debug, info, warn, error) @@ -175,6 +175,19 @@ fn default_site_url() -> String { "https://asepharyana.my.id".to_string() } +/// Deserialize a comma-separated string into a Vec. +/// Used for fields like cors_origins that come from a single env var. +fn deserialize_comma_separated<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let s = String::deserialize(deserializer)?; + Ok(s.split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect()) +} + fn default_db_max_connections() -> u32 { 100 } @@ -223,8 +236,7 @@ impl AppConfig { .add_source( Environment::with_prefix("APP") .separator("__") - .try_parsing(true) - .list_separator(","), + .try_parsing(true), ) // Map legacy env vars to new config structure .set_override_option("database_url", env::var("DATABASE_URL").ok())?