From 5c78958ec76ad0687c9a56dd08f4f54cc86714eb Mon Sep 17 00:00:00 2001 From: Manish Date: Wed, 18 Jun 2025 22:00:02 +1000 Subject: [PATCH] Imp: config to specify service bind and set default port as 7777 --- src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 180c20e..ccbce6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,10 +56,23 @@ impl AppConfig { #[derive(Debug, Deserialize)] struct Settings { + #[serde(default = "Settings::default_bind_localhost")] + bind: String, + #[serde(default = "Settings::default_port")] port: u16, apps: HashMap, } +impl Settings { + fn default_port() -> u16 { + 7777 + } + + fn default_bind_localhost() -> String { + String::from("127.0.0.1") + } +} + #[derive(Debug, Deserialize)] struct QueryParams { auth_token: String, @@ -342,7 +355,7 @@ async fn main() -> std::io::Result<()> { APPS_DEPLOYMENT_LOCK.get_or_init(|| RwLock::new(HashSet::new())); HttpServer::new(|| App::new().service(deploy)) - .bind(("127.0.0.1", settings.port))? + .bind((settings.bind.as_str(), settings.port))? .run() .await }