diff --git a/src/settings.rs b/src/settings.rs index 436fb1acf7..2c1f60db9b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -17,6 +17,7 @@ pub struct Settings { first_inscription_height: Option, height_limit: Option, hidden: Option>, + http_port: Option, index: Option, index_addresses: bool, index_cache_size: Option, @@ -133,6 +134,7 @@ impl Settings { .cloned() .collect(), ), + http_port: self.http_port.or(source.http_port), index: self.index.or(source.index), index_addresses: self.index_addresses || source.index_addresses, index_cache_size: self.index_cache_size.or(source.index_cache_size), @@ -169,6 +171,7 @@ impl Settings { first_inscription_height: options.first_inscription_height, height_limit: options.height_limit, hidden: None, + http_port: None, index: options.index, index_addresses: options.index_addresses, index_cache_size: options.index_cache_size, @@ -219,6 +222,14 @@ impl Settings { }) }; + let get_u16 = |key| { + env + .get(key) + .map(|int| int.parse::()) + .transpose() + .with_context(|| format!("failed to parse environment variable ORD_{key} as u16")) + }; + let get_u32 = |key| { env .get(key) @@ -226,6 +237,7 @@ impl Settings { .transpose() .with_context(|| format!("failed to parse environment variable ORD_{key} as u32")) }; + let get_usize = |key| { env .get(key) @@ -249,6 +261,7 @@ impl Settings { first_inscription_height: get_u32("FIRST_INSCRIPTION_HEIGHT")?, height_limit: get_u32("HEIGHT_LIMIT")?, hidden: inscriptions("HIDDEN")?, + http_port: get_u16("HTTP_PORT")?, index: get_path("INDEX"), index_addresses: get_bool("INDEX_ADDRESSES"), index_cache_size: get_usize("INDEX_CACHE_SIZE")?, @@ -280,6 +293,7 @@ impl Settings { first_inscription_height: None, height_limit: None, hidden: None, + http_port: None, index: None, index_addresses: true, index_cache_size: None, @@ -354,6 +368,7 @@ impl Settings { }), height_limit: self.height_limit, hidden: self.hidden, + http_port: self.http_port, index: Some(index), index_addresses: self.index_addresses, index_cache_size: Some(match self.index_cache_size { @@ -1011,6 +1026,7 @@ mod tests { ("FIRST_INSCRIPTION_HEIGHT", "2"), ("HEIGHT_LIMIT", "3"), ("HIDDEN", "6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0"), + ("HTTP_PORT", "8080"), ("INDEX", "index"), ("INDEX_CACHE_SIZE", "4"), ("INDEX_ADDRESSES", "1"), @@ -1056,6 +1072,7 @@ mod tests { .into_iter() .collect() ), + http_port: Some(8080), index: Some("index".into()), index_addresses: true, index_cache_size: Some(4), @@ -1120,6 +1137,7 @@ mod tests { first_inscription_height: Some(2), height_limit: Some(3), hidden: None, + http_port: None, index: Some("index".into()), index_addresses: true, index_cache_size: Some(4), diff --git a/tests/settings.rs b/tests/settings.rs index bfeeb51329..da228f2176 100644 --- a/tests/settings.rs +++ b/tests/settings.rs @@ -20,6 +20,7 @@ fn default() { "first_inscription_height": 767430, "height_limit": null, "hidden": \[\], + "http_port": null, "index": ".*index\.redb", "index_addresses": false, "index_cache_size": \d+,