feat: Add BOTSERVER_PORT environment variable override
All checks were successful
BotServer CI / build (push) Successful in 12m37s

- Check BOTSERVER_PORT env var before database config
- Override server_port from database if BOTSERVER_PORT is set
- Apply to both from_database() and from_env() config paths
- Allows easy port configuration via environment variable
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-02-06 12:56:52 -03:00
parent 125b9d4389
commit 84458b2a69

View file

@ -288,12 +288,17 @@ impl AppConfig {
smtp_server: get_str("EMAIL_SMTP_SERVER", "smtp.gmail.com"), smtp_server: get_str("EMAIL_SMTP_SERVER", "smtp.gmail.com"),
smtp_port: get_u16("EMAIL_SMTP_PORT", 587), smtp_port: get_u16("EMAIL_SMTP_PORT", 587),
}; };
let port = std::env::var("BOTSERVER_PORT")
.ok()
.and_then(|v| v.parse::<u16>().ok())
.unwrap_or_else(|| get_u16("server_port", 8080));
Ok(Self { Ok(Self {
drive, drive,
email, email,
server: ServerConfig { server: ServerConfig {
host: get_str("server_host", "0.0.0.0"), host: get_str("server_host", "0.0.0.0"),
port: get_u16("server_port", 8080), port,
base_url: config_map.get("server_base_url").cloned().unwrap_or_else(|| "http://localhost:8080".to_string()), base_url: config_map.get("server_base_url").cloned().unwrap_or_else(|| "http://localhost:8080".to_string()),
}, },
site_path: { site_path: {
@ -321,12 +326,17 @@ impl AppConfig {
smtp_server: "smtp.gmail.com".to_string(), smtp_server: "smtp.gmail.com".to_string(),
smtp_port: 587, smtp_port: 587,
}; };
let port = std::env::var("BOTSERVER_PORT")
.ok()
.and_then(|v| v.parse::<u16>().ok())
.unwrap_or(8080);
Ok(Self { Ok(Self {
drive: minio, drive: minio,
email, email,
server: ServerConfig { server: ServerConfig {
host: "0.0.0.0".to_string(), host: "0.0.0.0".to_string(),
port: 8080, port,
base_url: "http://localhost:8080".to_string(), base_url: "http://localhost:8080".to_string(),
}, },