From 7cf06683f29b5bd725b9ec15e2ffac77e039e51b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 May 2020 13:50:25 +0200 Subject: Add port configuration/cli argument Signed-off-by: Matthias Beyer --- Cargo.toml | 1 - distrox.toml | 3 +++ src/cli.rs | 7 +++++++ src/configuration.rs | 6 ++++++ src/main.rs | 2 +- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5d224b..daf699a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,5 @@ web-view = "0.6" handlebars = "3" actix-rt = "1" actix-web = "2" -port_check = "0.1" failure = "0.1" pidlock = { git = "https://github.com/matthiasbeyer/pidlock", branch = "my-master" } diff --git a/distrox.toml b/distrox.toml index 071b20a..f150886 100644 --- a/distrox.toml +++ b/distrox.toml @@ -4,6 +4,9 @@ ipfs-api-url = "127.0.0.1" # The API Port ipfs-api-port = 5001 +# The Port for the app itself +app-port = 5002 + # Whether to automatically "ipfs pin" chain objects autoserve-chains = true diff --git a/src/cli.rs b/src/cli.rs index 1eae246..c91b653 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,6 +12,9 @@ pub struct CLI { #[structopt(short, long)] trace: bool, + #[structopt(short, long)] + port: Option, + #[structopt(parse(from_os_str))] configfile: Option, @@ -23,6 +26,10 @@ impl CLI { pub fn cmd(&self) -> Option<&Command> { self.cmd.as_ref() } + + pub fn port(&self) -> Option { + self.port.as_ref().map(|p| *p) + } } #[derive(Debug, PartialEq, StructOpt)] diff --git a/src/configuration.rs b/src/configuration.rs index c0d64b5..5b39090 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -15,6 +15,11 @@ pub struct Configuration { /// The Port of the API api_port: u16, + #[serde(rename = "app-port")] + #[get] + /// The Port of the App itself + app_port: u16, + #[serde(rename = "autoserve-chains")] #[get] /// Whether to automatically "ipfs pin" chain objects @@ -84,6 +89,7 @@ impl Default for Configuration { Configuration { api_url : String::from("127.0.0.1"), api_port : 5001, + app_port : 5002, autoserve_chains : true, autoserve_text_posts : true, serve_blocked : false, diff --git a/src/main.rs b/src/main.rs index 7561e0c..3e0d972 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,6 @@ fn start_server(cli: &CLI) -> bool { async fn main() -> Result<()> { let cli = cli()?; let _ = env_logger::init(); - let port = port_check::free_local_port().expect("Could not find free port"); debug!("Logger initialized"); let config_file_name = PathBuf::from("distrox.toml"); @@ -88,6 +87,7 @@ async fn main() -> Result<()> { ::toml::from_str(&configstr)? }; + let port = cli.port().unwrap_or_else(|| *config.get_app_port()); let adr = format!("127.0.0.1:{}", port); if start_server(&cli) { -- cgit v1.2.3