simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 654245fbe3ef2deb0fe87b9a54646726a7cdfec2
parent df1a5a44600e1f0aa0820c59f32d2fc59a194734
Author: Silas Brack <silasbrack@gmail.com>
Date:   Sat, 13 Jun 2026 13:43:05 +0200

refactor: use ADDR and SMTP_ADDR env vars directly

No more PORT/SMTP_HOST/SMTP_PORT concatenation. Env vars match
what the code uses. Removed require_parse helper — only DEBUG
needed parsing and == "true" is clearer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
M.env.example | 5++---
Msrc/config.rs | 26+++++++-------------------
2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/.env.example b/.env.example @@ -1,7 +1,6 @@ DB_PATH=data/app.db DEBUG=true -PORT=8000 -SMTP_HOST=localhost -SMTP_PORT=25 +ADDR=0.0.0.0:8000 +SMTP_ADDR=localhost:25 SMTP_FROM=noreply@example.com SITE_URL=http://localhost:8000 diff --git a/src/config.rs b/src/config.rs @@ -10,36 +10,24 @@ pub struct Config { pub site_url: String, } -fn require(name: &str) -> String { +fn env(name: &str) -> String { env::var(name).unwrap_or_else(|_| panic!("{name} must be set")) } -fn require_parse<T: std::str::FromStr>(name: &str) -> T -where - T::Err: std::fmt::Display, -{ - let val = require(name); - val.parse().unwrap_or_else(|e| panic!("{name}={val}: {e}")) -} - impl Config { pub fn from_env() -> Self { - let port: u16 = require_parse("PORT"); - let smtp_host = require("SMTP_HOST"); - let smtp_port: u16 = require_parse("SMTP_PORT"); - Self { - db_path: require("DB_PATH"), + db_path: env("DB_PATH"), jwt_secret: { use rand::Rng; let bytes: [u8; 32] = rand::thread_rng().gen(); bytes.iter().map(|b| format!("{:02x}", b)).collect() }, - debug: require_parse("DEBUG"), - addr: format!("0.0.0.0:{port}"), - smtp_addr: format!("{smtp_host}:{smtp_port}"), - smtp_from: require("SMTP_FROM"), - site_url: require("SITE_URL"), + debug: env("DEBUG") == "true", + addr: env("ADDR"), + smtp_addr: env("SMTP_ADDR"), + smtp_from: env("SMTP_FROM"), + site_url: env("SITE_URL"), } } }