File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,9 +87,32 @@ async fn main() {
8787 . route ( "/" , axum:: routing:: get ( static_handler) )
8888 . route ( "/{*path}" , axum:: routing:: get ( static_handler) ) ;
8989
90- let api_address = config. bot . ip . unwrap_or_else ( || "0.0.0.0" . to_string ( ) ) ;
90+ let bind_address = config
91+ . bot
92+ . ip
93+ . as_ref ( )
94+ . and_then ( |ip| {
95+ if ip. parse :: < std:: net:: IpAddr > ( ) . is_ok ( ) {
96+ Some ( ip. clone ( ) )
97+ } else {
98+ None
99+ }
100+ } )
101+ . unwrap_or_else ( || "0.0.0.0" . to_string ( ) ) ;
91102
92- let listener = tokio:: net:: TcpListener :: bind ( format ! ( "{}:{}" , api_address, 3002 ) ) . await . unwrap ( ) ;
103+ let listener =
104+ match tokio:: net:: TcpListener :: bind ( format ! ( "{}:3002" , bind_address) ) . await {
105+ Ok ( l) => l,
106+ Err ( e) => {
107+ eprintln ! (
108+ "Failed to bind to {}:3002 ({}), falling back to 0.0.0.0:3002" ,
109+ bind_address, e
110+ ) ;
111+ tokio:: net:: TcpListener :: bind ( "0.0.0.0:3002" )
112+ . await
113+ . expect ( "Failed to bind to 0.0.0.0:3002" )
114+ }
115+ } ;
93116 println ! ( "listening on {}" , listener. local_addr( ) . unwrap( ) ) ;
94117
95118 axum:: serve (
You can’t perform that action at this time.
0 commit comments