Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen on 127.0.0.1 to avoid firewall popup on macOS #2911

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading