Skip to content

Commit

Permalink
feat: resolve serve addresses with DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Sep 19, 2024
1 parent e3cd078 commit 0d0cbd3
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 22 deletions.
140 changes: 139 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ directories = "5"
dunce = "1"
flate2 = "1"
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
hickory-resolver = { version = "0.24.1", features = ["system-config"] }
homedir = "0.3.3"
htmlescape = "0.3.1"
http = "1.1"
Expand Down
4 changes: 3 additions & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ addresses = ["127.0.0.1"]
# The port to serve on.
port = 8080
# Aliases to serve, typically found in an /etc/hosts file.
aliases = ["http://localhost.mywebsite.com"]
# aliases = ["http://localhost.mywebsite.com"]
# Disable the reverse DNS lookup during startup
disable_address_lookup = false
# Open a browser tab once the initial build is complete.
open = false
# Whether to disable fallback to index.html for missing files.
Expand Down
21 changes: 13 additions & 8 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@
"format": "ip"
}
},
"aliases": {
"description": "The aliases to serve on.",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"disable_address_lookup": {
"description": "Disable the reverse DNS lookup during startup",
"default": false,
"type": "boolean"
},
"headers": {
"description": "Additional headers to send in responses",
"default": {},
Expand Down Expand Up @@ -454,14 +467,6 @@
"format": "uint16",
"minimum": 0.0
},
"aliases": {
"description": "The aliases to serve on.",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"prefer_address_family": {
"anyOf": [
{
Expand Down
7 changes: 7 additions & 0 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub struct Serve {
/// The aliases to serve on
#[arg(long, env = "TRUNK_SERVE_ALIAS")]
pub alias: Option<Vec<String>>,
/// Disable the lookup of addresses serving on during startup
#[arg(long, env = "TRUNK_SERVE_DISABLE_ADDRESS_LOOKUP")]
#[arg(default_missing_value="true", num_args=0..=1)]
pub disable_address_lookup: Option<bool>,
/// Open a browser tab once the initial build is complete [default: false]
#[arg(long, env = "TRUNK_SERVE_OPEN")]
#[arg(default_missing_value="true", num_args=0..=1)]
Expand Down Expand Up @@ -110,6 +114,7 @@ impl Serve {
prefer_address_family,
port,
alias,
disable_address_lookup,
open,
proxy:
ProxyArgs {
Expand All @@ -136,6 +141,8 @@ impl Serve {
config.serve.addresses = address.unwrap_or(config.serve.addresses);
config.serve.port = port.unwrap_or(config.serve.port);
config.serve.aliases = alias.unwrap_or(config.serve.aliases);
config.serve.disable_address_lookup =
disable_address_lookup.unwrap_or(config.serve.disable_address_lookup);
config.serve.open = open.unwrap_or(config.serve.open);
config.serve.prefer_address_family =
prefer_address_family.or(config.serve.prefer_address_family);
Expand Down
4 changes: 4 additions & 0 deletions src/config/models/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct Serve {
pub addresses: Vec<IpAddr>,
#[serde(default)]
pub prefer_address_family: Option<AddressFamily>,
/// Disable the reverse DNS lookup during startup
#[serde(default)]
pub disable_address_lookup: bool,
/// The port to serve on [default: 8080]
#[serde(default = "default::port")]
pub port: u16,
Expand Down Expand Up @@ -90,6 +93,7 @@ impl Default for Serve {
aliases: vec![],
prefer_address_family: None,
port: default::port(),
disable_address_lookup: false,
open: false,
no_autoreload: false,
headers: Default::default(),
Expand Down
4 changes: 4 additions & 0 deletions src/config/rt/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct RtcServe {
pub port: u16,
/// The aliases to serve on.
pub aliases: Vec<String>,
/// Disable the DNS lookup during startup
pub disable_address_lookup: bool,
/// Open a browser tab once the initial build is complete.
pub open: bool,
/// Any proxies configured to run along with the server.
Expand Down Expand Up @@ -79,6 +81,7 @@ impl RtcServe {
prefer_address_family,
port,
aliases,
disable_address_lookup,
open: _,
// auto-reload is handle by the builder options
no_autoreload: _,
Expand Down Expand Up @@ -110,6 +113,7 @@ impl RtcServe {
addresses: build_address_list(prefer_address_family, addresses),
port,
aliases,
disable_address_lookup,
open,
proxies: config.proxies.0,
no_spa,
Expand Down
Loading

0 comments on commit 0d0cbd3

Please sign in to comment.