fix binding to unspecified addr on v4 and v6

main
xenofem 2022-05-23 21:21:57 -04:00
parent 11f2b8f626
commit 43d03869ab
1 changed files with 13 additions and 18 deletions

View File

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