fix binding to unspecified addr on v4 and v6

This commit is contained in:
xenofem 2022-05-23 21:21:57 -04:00
parent 11f2b8f626
commit 43d03869ab

View file

@ -200,7 +200,7 @@ async fn main() -> std::io::Result<()> {
}); });
start_reaper(data.clone()); start_reaper(data.clone());
HttpServer::new(move || { let server = HttpServer::new(move || {
App::new() App::new()
.app_data(data.clone()) .app_data(data.clone())
.wrap(if data.config.reverse_proxy { .wrap(if data.config.reverse_proxy {
@ -213,25 +213,20 @@ async fn main() -> std::io::Result<()> {
.service(check_upload_password) .service(check_upload_password)
.service(upload_limits) .service(upload_limits)
.service(actix_files::Files::new("/", static_dir.clone()).index_file("index.html")) .service(actix_files::Files::new("/", static_dir.clone()).index_file("index.html"))
}) });
.bind((
if reverse_proxy { if reverse_proxy {
std::net::Ipv4Addr::LOCALHOST server
} else { .bind((std::net::Ipv4Addr::LOCALHOST, port))?
std::net::Ipv4Addr::UNSPECIFIED .bind((std::net::Ipv6Addr::LOCALHOST, port))?
}, } else {
port, // Looks like this also picks up IPv4?
))? // Binding 0.0.0.0 and :: on the same port fails with an error.
.bind(( server.bind((std::net::Ipv6Addr::UNSPECIFIED, port))?
if reverse_proxy { }
std::net::Ipv6Addr::LOCALHOST
} else {
std::net::Ipv6Addr::UNSPECIFIED
},
port,
))?
.run() .run()
.await?; .await?;
Ok(()) Ok(())
} }