From 3f3e069aaba7c143d43d5af77b2b3ac73d4d4523 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 23 Jun 2024 11:15:59 +0200 Subject: [PATCH] Add an ENV for SERVER_ADDRESS --- snow-scanner/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/snow-scanner/src/main.rs b/snow-scanner/src/main.rs index 4a5b6fb..79a9ab0 100644 --- a/snow-scanner/src/main.rs +++ b/snow-scanner/src/main.rs @@ -12,7 +12,7 @@ use sha2::Sha256; use std::str::FromStr; use std::sync::Mutex; use std::time::Duration; -use std::{fmt, thread}; +use std::{env, fmt, thread}; use uuid7::Uuid; use hickory_client::client::SyncClient; @@ -369,7 +369,13 @@ fn get_dns_client() -> SyncClient { } fn main() -> Result<()> { - println!("Now listening on localhost:8000"); + let server_address: String = if let Ok(env) = env::var("SERVER_ADDRESS") { + env + } else { + "localhost:8000".to_string() + }; + + println!("Now listening on {}", server_address); let conn = Mutex::new(get_connection()); conn.lock() @@ -414,7 +420,7 @@ fn main() -> Result<()> { thread::sleep(two_hundred_millis); }); - rouille::start_server("localhost:8000", move |request| { + rouille::start_server(server_address, move |request| { router!(request, (GET) (/) => { rouille::Response::html(FORM)