Skip to content

Commit

Permalink
Listen on 127.0.0.1 to avoid firewall popup on macOS (ordinals#2911)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored and torkelrogstad committed Mar 11, 2024
1 parent e57c2cf commit 5abbde2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ impl Display for StaticHtml {
pub(crate) struct Server {
#[arg(
long,
default_value = "0.0.0.0",
help = "Listen on <ADDRESS> for incoming requests."
help = "Listen on <ADDRESS> for incoming requests. [default: 0.0.0.0]"
)]
address: String,
address: Option<String>,
#[arg(
long,
help = "Request ACME TLS certificate for <ACME_DOMAIN>. This ord instance must be reachable at <ACME_DOMAIN>:443 to respond to Let's Encrypt ACME challenges."
Expand All @@ -145,13 +144,13 @@ pub(crate) struct Server {
csp_origin: Option<String>,
#[arg(
long,
help = "Listen on <HTTP_PORT> for incoming HTTP requests. [default: 80]."
help = "Listen on <HTTP_PORT> for incoming HTTP requests. [default: 80]"
)]
http_port: Option<u16>,
#[arg(
long,
group = "port",
help = "Listen on <HTTPS_PORT> for incoming HTTPS requests. [default: 443]."
help = "Listen on <HTTPS_PORT> for incoming HTTPS requests. [default: 443]"
)]
https_port: Option<u16>,
#[arg(long, help = "Store ACME TLS certificates in <ACME_CACHE>.")]
Expand Down Expand Up @@ -342,7 +341,18 @@ impl Server {
port: u16,
config: SpawnConfig,
) -> Result<task::JoinHandle<io::Result<()>>> {
let addr = (self.address.as_str(), port)
let address = match &self.address {
Some(address) => address.as_str(),
None => {
if cfg!(test) || integration_test() {
"127.0.0.1"
} else {
"0.0.0.0"
}
}
};

let addr = (address, port)
.to_socket_addrs()?
.next()
.ok_or_else(|| anyhow!("failed to get socket addrs"))?;
Expand Down

0 comments on commit 5abbde2

Please sign in to comment.