From 46b838656a9cd4725c6b1cc58f5be55097a4ac58 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 28 Mar 2022 21:10:59 +0800 Subject: Bugfix: Specify `localhost` listen endpoint will cause a panic. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bfb59e..c61a8d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -829,7 +829,7 @@ dependencies = [ [[package]] name = "kimikuri_rs" -version = "0.5.0" +version = "0.5.1" dependencies = [ "bs58", "futures", diff --git a/Cargo.toml b/Cargo.toml index 84bd6d3..1d54179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kimikuri_rs" -version = "0.5.0" +version = "0.5.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index e85b74e..d54a97c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::{io, path}; use std::collections::HashMap; use std::convert::Infallible; -use std::net::SocketAddr; +use std::net::{SocketAddr, ToSocketAddrs}; use std::str::FromStr; use teloxide::prelude2::*; @@ -104,7 +104,11 @@ async fn main() { info!("Starting HTTP server..."); let endpoint: SocketAddr = config.listen.parse() - .expect("Cannot parse `listen` as endpoint."); + .unwrap_or_else(|_| config.listen + .to_socket_addrs() + .expect("Cannot resolve endpoint.") + .next() + .expect("Cannot resolve endpoint.")); info!("Start listening on {}", endpoint); tokio::spawn(warp::serve(routes).run(endpoint)); -- cgit v1.2.3