From d202afeaf5e81532217b6e6227990cf52b507604 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Sat, 21 Oct 2023 12:30:56 +0100 Subject: [PATCH] allow binding server to hostname (#1318) --- atuin-server/src/lib.rs | 10 +++------- atuin/src/command/server.rs | 8 +++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/atuin-server/src/lib.rs b/atuin-server/src/lib.rs index 007ad5c..6778b09 100644 --- a/atuin-server/src/lib.rs +++ b/atuin-server/src/lib.rs @@ -1,9 +1,6 @@ #![forbid(unsafe_code)] -use std::{ - future::Future, - net::{IpAddr, SocketAddr, TcpListener}, -}; +use std::{future::Future, net::TcpListener}; use atuin_server_database::Database; use axum::Server; @@ -43,13 +40,12 @@ async fn shutdown_signal() { pub async fn launch( settings: Settings, - host: String, + host: &str, port: u16, ) -> Result<()> { - let host = host.parse::()?; launch_with_listener::( settings, - TcpListener::bind(SocketAddr::new(host, port)).context("could not connect to socket")?, + TcpListener::bind((host, port)).context("could not connect to socket")?, shutdown_signal(), ) .await diff --git a/atuin/src/command/server.rs b/atuin/src/command/server.rs index b56fde2..bfecdd7 100644 --- a/atuin/src/command/server.rs +++ b/atuin/src/command/server.rs @@ -37,12 +37,10 @@ impl Cmd { match self { Self::Start { host, port } => { let settings = Settings::new().wrap_err("could not load server settings")?; - let host = host - .as_ref() - .map_or(settings.host.clone(), std::string::ToString::to_string); - let port = port.map_or(settings.port, |p| p); + let host = host.as_ref().unwrap_or(&settings.host).clone(); + let port = port.unwrap_or(settings.port); - launch::(settings, host, port).await + launch::(settings, &host, port).await } Self::DefaultConfig => { println!("{}", example_config());