diff --git a/README.md b/README.md index a16d72a..655a69b 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ A Rust HTTP service that allows you to watch videos together with friends. ```shell $ cargo run --release -# The server should listen at http://127.0.0.1:3000/ by default +# The server should listen at http://127.0.0.1:3000/ by default, +# but you can use the HOST and PORT environment variables to override this ``` diff --git a/src/main.rs b/src/main.rs index 2a47301..8b0fbba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Mutex}; +use std::{collections::HashMap, net::IpAddr, sync::Mutex}; use once_cell::sync::Lazy; use serde_json::json; @@ -136,5 +136,13 @@ async fn main() { .or(warb::path::end().and(warb::fs::file("frontend/index.html"))) .or(warb::fs::dir("frontend")); - warb::serve(routes).run(([127, 0, 0, 1], 3000)).await; + let host = std::env::var("HOST") + .ok() + .and_then(|s| s.parse::().ok()) + .unwrap_or_else(|| [127, 0, 0, 1].into()); + let port = std::env::var("PORT") + .ok() + .and_then(|s| s.parse::().ok()) + .unwrap_or(3000); + warb::serve(routes).run((host, port)).await; }