From 9c7deaeb653e1db117f8a13da9f911911762a04a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 28 Mar 2022 02:08:22 +0100 Subject: [PATCH] server: Move listening address config resolution to config Signed-off-by: Ian Jackson --- daemon/main.rs | 9 +-------- src/config.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/daemon/main.rs b/daemon/main.rs index f472430a..b1113768 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -532,14 +532,7 @@ async fn main() -> Result<(),StartupError> { let mut http = http .disable_signals(); - let addrs: &[&dyn IpAddress] = &[ - &Ipv6Addr::LOCALHOST, - &Ipv4Addr::LOCALHOST, - ]; - let port = c.http_port.unwrap_or(8000); - - for addr in addrs { - let addr = addr.with_port(port); + for addr in &c.listen { http = http.bind(addr) .with_context(|| format!("bind {:?}", addr))?; } diff --git a/src/config.rs b/src/config.rs index ef2cc6ca..d3cd1182 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,7 +63,7 @@ pub struct ServerConfig { save_dir: String, pub command_socket: String, pub debug: bool, - pub http_port: Option, + pub listen: Vec, pub public_url: String, pub sse_wildcard_url: Option<(String, String)>, pub template_dir: String, @@ -281,9 +281,18 @@ impl ServerConfigSpec { let check_bundled_sources = check_bundled_sources.unwrap_or(true); + let http_port = http_port.unwrap_or(8000); + let addrs: &[&dyn IpAddress] = &[ + &Ipv6Addr::LOCALHOST, + &Ipv4Addr::LOCALHOST, + ]; + let listen = addrs.iter() + .map(|addr| addr.with_port(http_port)) + .collect(); + let server = ServerConfig { save_dir, command_socket, debug, - http_port, public_url, sse_wildcard_url, + listen, public_url, sse_wildcard_url, template_dir, specs_dir, nwtemplate_dir, wasm_dir, libexec_dir, bundled_sources, shapelibs, sendmail, usvg_bin, debug_js_inject, check_bundled_sources, game_rng, prctx, -- 2.30.2