/// Environment-based configuration for all upstream services and the gateway itself. #[derive(Debug, Clone)] pub struct AppConfig { pub host: String, pub port: u16, /// Public-facing URL of this backend, used to rewrite tile URLs in style.json. /// Set via PUBLIC_URL env var, defaults to http://localhost:8080. pub public_url: String, pub martin_url: String, pub photon_url: String, pub osrm_driving_url: String, pub osrm_walking_url: String, pub osrm_cycling_url: String, pub database_url: String, pub redis_url: String, pub offline_data_dir: String, } impl AppConfig { /// Load configuration from environment variables with sensible defaults /// for docker-compose deployment. pub fn from_env() -> Self { Self { host: std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".into()), port: std::env::var("PORT") .ok() .and_then(|v| v.parse().ok()) .unwrap_or(8080), public_url: std::env::var("PUBLIC_URL") .unwrap_or_else(|_| "http://localhost:8080".into()), martin_url: std::env::var("MARTIN_URL") .unwrap_or_else(|_| "http://martin:3000".into()), photon_url: std::env::var("PHOTON_URL") .unwrap_or_else(|_| "http://photon:2322".into()), osrm_driving_url: std::env::var("OSRM_DRIVING_URL") .unwrap_or_else(|_| "http://osrm-driving:5000".into()), osrm_walking_url: std::env::var("OSRM_WALKING_URL") .unwrap_or_else(|_| "http://osrm-walking:5000".into()), osrm_cycling_url: std::env::var("OSRM_CYCLING_URL") .unwrap_or_else(|_| "http://osrm-cycling:5000".into()), database_url: std::env::var("DATABASE_URL") .unwrap_or_else(|_| "postgres://maps:maps@postgis:5432/maps".into()), redis_url: std::env::var("REDIS_URL") .unwrap_or_else(|_| "redis://redis:6379".into()), offline_data_dir: std::env::var("OFFLINE_DATA_DIR") .unwrap_or_else(|_| "/data/offline".into()), } } /// Return the OSRM base URL for a given routing profile. pub fn osrm_url_for_profile(&self, profile: &str) -> Option<&str> { match profile { "driving" => Some(&self.osrm_driving_url), "walking" => Some(&self.osrm_walking_url), "cycling" => Some(&self.osrm_cycling_url), _ => None, } } }