44mod maven;
55mod types;
66
7- use std:: { net:: Ipv4Addr , time:: Duration } ;
7+ use std:: { net:: SocketAddr , time:: Duration } ;
88
99use actix_web:: { App , HttpServer , web} ;
1010use api:: v1:: { ApiData , CacheKey , CacheValue , ETagType } ;
@@ -18,12 +18,17 @@ use url::Url;
1818#[ derive( Parser , Clone ) ]
1919#[ clap( version, about, long_about = None ) ]
2020struct AppCommand {
21- /// The port for the HTTP server to listen on
22- #[ clap( long, env = "BACKEND_LISTEN_PORT" , default_value_t = 8080 ) ]
23- pub port : u16 ,
24- /// The host address for the HTTP server to listen on
25- #[ clap( long, env = "BACKEND_LISTEN_HOST" , default_value_t = Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ]
26- pub host : Ipv4Addr ,
21+ /// The addresses (IP and port) for the HTTP server to bind to.
22+ ///
23+ /// Multiple bind addresses can be either split by comma, or passed as
24+ /// multiple flags.
25+ #[ clap(
26+ long,
27+ env = "BACKEND_LISTEN_PORT" ,
28+ value_delimiter = ',' ,
29+ default_value = "[::]:8080"
30+ ) ]
31+ pub bind : Vec < SocketAddr > ,
2732 /// If passed, the server will be downgraded to HTTP/1.1 rather than HTTP/2
2833 #[ clap( long, env = "BACKEND_USE_HTTP1" , default_value_t = false ) ]
2934 pub http1 : bool ,
@@ -46,7 +51,6 @@ async fn main() {
4651 env_logger:: init ( ) ;
4752
4853 let args = AppCommand :: parse ( ) ;
49- let listen_args = ( args. host , args. port ) ;
5054 let data = web:: Data :: new ( ApiData {
5155 internal_maven_url : args. internal_maven_url . map ( |url| url. to_string ( ) ) ,
5256 public_maven_url : args. public_maven_url . to_string ( ) ,
@@ -76,14 +80,19 @@ async fn main() {
7680 . build ( )
7781 } ) ;
7882
79- HttpServer :: new ( move || {
83+ let mut server = HttpServer :: new ( move || {
8084 App :: new ( )
8185 . app_data ( data. clone ( ) )
8286 . configure ( api:: v1:: configure ( ) )
83- } )
84- . bind_auto_h2c ( listen_args)
85- . expect ( "Unable to bind on specified IP and port" )
86- . run ( )
87- . await
88- . expect ( "Unable to start HTTP server" ) ;
87+ } ) ;
88+
89+ // Call .bind for each address, as using multiple in the same call can silently
90+ // fail
91+ for bind_addr in args. bind {
92+ server = server
93+ . bind_auto_h2c ( bind_addr)
94+ . expect ( "Unable to bind on specified address" ) ;
95+ }
96+
97+ server. run ( ) . await . expect ( "Unable to start HTTP server" ) ;
8998}
0 commit comments