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. --- src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') 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