From 263e3e0255d14e0c8ab1e09d7721866cdef4a6a4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 23 Nov 2019 12:19:45 -0500 Subject: stop hardcoding the list and watch urls --- teleterm/src/cmd/web.rs | 1 + teleterm/src/config.rs | 25 +++++++++++++++++++++++++ teleterm/src/web.rs | 3 +++ 3 files changed, 29 insertions(+) (limited to 'teleterm/src') diff --git a/teleterm/src/cmd/web.rs b/teleterm/src/cmd/web.rs index 37f2f70..0ec1daa 100644 --- a/teleterm/src/cmd/web.rs +++ b/teleterm/src/cmd/web.rs @@ -19,6 +19,7 @@ impl crate::config::Config for Config { ) -> Box + Send> { Box::new(crate::web::Server::new( self.web.listen_address, + self.web.public_address.clone(), self.web.server_address.clone(), )) } diff --git a/teleterm/src/config.rs b/teleterm/src/config.rs index 390ee4c..6dd18b9 100644 --- a/teleterm/src/config.rs +++ b/teleterm/src/config.rs @@ -18,6 +18,7 @@ const LOGIN_RECURSE_CENTER_OPTION: &str = "login-recurse-center"; const MAX_FRAME_LENGTH_OPTION: &str = "max-frame-length"; const PLAY_AT_START_OPTION: &str = "play-at-start"; const PLAYBACK_RATIO_OPTION: &str = "playback-ratio"; +const PUBLIC_ADDRESS_OPTION: &str = "public-address"; const READ_TIMEOUT_OPTION: &str = "read-timeout-secs"; const SERVER_ADDRESS_OPTION: &str = "server-address"; const TLS_IDENTITY_FILE_OPTION: &str = "tls-identity-file"; @@ -561,6 +562,9 @@ pub struct Web { )] pub listen_address: std::net::SocketAddr, + #[serde(default = "default_web_public_address")] + pub public_address: String, + #[serde( deserialize_with = "connect_address", default = "default_connect_address" @@ -572,6 +576,8 @@ impl Web { pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { let listen_address_help = "Host and port to listen on (defaults to localhost:4145)"; + let public_address_help = + "Host and port that the web server will be publicly available on (defaults to the listen address)"; let server_address_help = "Host and port of the teleterm server (defaults to localhost:4144)"; app.arg( @@ -581,6 +587,13 @@ impl Web { .value_name("HOST:PORT") .help(listen_address_help), ) + .arg( + clap::Arg::with_name(PUBLIC_ADDRESS_OPTION) + .long(PUBLIC_ADDRESS_OPTION) + .takes_value(true) + .value_name("HOST:PORT") + .help(public_address_help), + ) .arg( clap::Arg::with_name(SERVER_ADDRESS_OPTION) .long(SERVER_ADDRESS_OPTION) @@ -601,6 +614,13 @@ impl Web { .parse() .context(crate::error::ParseAddr)?; } + if matches.is_present(PUBLIC_ADDRESS_OPTION) { + self.public_address = + matches.value_of(PUBLIC_ADDRESS_OPTION).unwrap().to_string(); + } else if matches.is_present(LISTEN_ADDRESS_OPTION) { + self.public_address = + matches.value_of(LISTEN_ADDRESS_OPTION).unwrap().to_string(); + } if matches.is_present(SERVER_ADDRESS_OPTION) { let address = matches.value_of(SERVER_ADDRESS_OPTION).unwrap(); self.server_address = to_connect_address(address)?; @@ -613,6 +633,7 @@ impl Default for Web { fn default() -> Self { Self { listen_address: default_web_listen_address(), + public_address: default_web_public_address(), server_address: default_connect_address(), } } @@ -622,6 +643,10 @@ fn default_web_listen_address() -> std::net::SocketAddr { to_listen_address(DEFAULT_WEB_LISTEN_ADDRESS).unwrap() } +fn default_web_public_address() -> String { + DEFAULT_WEB_LISTEN_ADDRESS.to_string() +} + #[derive(serde::Deserialize, Debug)] pub struct Command { #[serde(default = "default_command")] diff --git a/teleterm/src/web.rs b/teleterm/src/web.rs index 991f543..992b79d 100644 --- a/teleterm/src/web.rs +++ b/teleterm/src/web.rs @@ -12,6 +12,7 @@ use gotham::state::FromState as _; struct Config { title: String, server_address: (String, std::net::SocketAddr), + public_address: String, } pub struct Server { @@ -21,11 +22,13 @@ pub struct Server { impl Server { pub fn new( listen_address: std::net::SocketAddr, + public_address: String, server_address: (String, std::net::SocketAddr), ) -> Self { let data = Config { title: "teleterm".to_string(), server_address, + public_address, }; Self { server: Box::new(gotham::init_server( -- cgit v1.2.3-54-g00ecf