From 1d61bd040fbd6afe81f111be6ccac4cd2be290b8 Mon Sep 17 00:00:00 2001 From: Guillaume Deconinck <113656593+GuillaumeDecMeetsMore@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:06:59 +0900 Subject: [PATCH] [NO-ISSUE] fix: allow to bind other host with env var (#38) * fix: allow to bind other host with env var * fix: use app name in env vars --- scheduler/crates/api/src/lib.rs | 8 +++++--- scheduler/crates/infra/src/config.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scheduler/crates/api/src/lib.rs b/scheduler/crates/api/src/lib.rs index 4164d5b7..b94fccf5 100644 --- a/scheduler/crates/api/src/lib.rs +++ b/scheduler/crates/api/src/lib.rs @@ -23,7 +23,7 @@ use nettu_scheduler_domain::{ ID, }; use nettu_scheduler_infra::NettuContext; -use tracing::warn; +use tracing::{info, warn}; use tracing_actix_web::TracingLogger; pub fn configure_server_api(cfg: &mut web::ServiceConfig) { @@ -82,8 +82,10 @@ impl Application { async fn configure_server(context: NettuContext) -> Result<(Server, u16), std::io::Error> { let port = context.config.port; - let address = format!("127.0.0.1:{}", port); - let listener = TcpListener::bind(address)?; + let address = std::env::var("NITTEI_HOST").unwrap_or_else(|_| "127.0.0.1".to_string()); + let address_and_port = format!("{}:{}", address, port); + info!("Starting server on: {}", address_and_port); + let listener = TcpListener::bind(address_and_port)?; let port = listener.local_addr().unwrap().port(); let server = HttpServer::new(move || { diff --git a/scheduler/crates/infra/src/config.rs b/scheduler/crates/infra/src/config.rs index 93d4065f..3b8403dd 100644 --- a/scheduler/crates/infra/src/config.rs +++ b/scheduler/crates/infra/src/config.rs @@ -34,7 +34,7 @@ impl Config { } }; let default_port = "5000"; - let port = std::env::var("PORT").unwrap_or_else(|_| default_port.into()); + let port = std::env::var("NITTEI_PORT").unwrap_or_else(|_| default_port.into()); let port = match port.parse::() { Ok(port) => port, Err(_) => {