diff options
author | Keuin <[email protected]> | 2022-03-28 21:10:59 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-03-28 21:10:59 +0800 |
commit | 46b838656a9cd4725c6b1cc58f5be55097a4ac58 (patch) | |
tree | 4ae4e07bbfe814f3f8dbf853d78f3fdc734513b6 /src | |
parent | 3c8531e8a4d3a23c2f4f3875bc30d2cbe103ec47 (diff) |
Bugfix: Specify `localhost` listen endpoint will cause a panic.v0.5.1
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 8 |
1 files changed, 6 insertions, 2 deletions
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)); |