Skip to content

Commit 0d0cbd3

Browse files
committed
feat: resolve serve addresses with DNS
1 parent e3cd078 commit 0d0cbd3

File tree

8 files changed

+233
-22
lines changed

8 files changed

+233
-22
lines changed

Cargo.lock

Lines changed: 139 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ directories = "5"
3333
dunce = "1"
3434
flate2 = "1"
3535
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
36+
hickory-resolver = { version = "0.24.1", features = ["system-config"] }
3637
homedir = "0.3.3"
3738
htmlescape = "0.3.1"
3839
http = "1.1"

Trunk.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ addresses = ["127.0.0.1"]
4343
# The port to serve on.
4444
port = 8080
4545
# Aliases to serve, typically found in an /etc/hosts file.
46-
aliases = ["http://localhost.mywebsite.com"]
46+
# aliases = ["http://localhost.mywebsite.com"]
47+
# Disable the reverse DNS lookup during startup
48+
disable_address_lookup = false
4749
# Open a browser tab once the initial build is complete.
4850
open = false
4951
# Whether to disable fallback to index.html for missing files.

schemas/config.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,19 @@
419419
"format": "ip"
420420
}
421421
},
422+
"aliases": {
423+
"description": "The aliases to serve on.",
424+
"default": [],
425+
"type": "array",
426+
"items": {
427+
"type": "string"
428+
}
429+
},
430+
"disable_address_lookup": {
431+
"description": "Disable the reverse DNS lookup during startup",
432+
"default": false,
433+
"type": "boolean"
434+
},
422435
"headers": {
423436
"description": "Additional headers to send in responses",
424437
"default": {},
@@ -454,14 +467,6 @@
454467
"format": "uint16",
455468
"minimum": 0.0
456469
},
457-
"aliases": {
458-
"description": "The aliases to serve on.",
459-
"default": [],
460-
"type": "array",
461-
"items": {
462-
"type": "string"
463-
}
464-
},
465470
"prefer_address_family": {
466471
"anyOf": [
467472
{

src/cmd/serve.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ pub struct Serve {
3030
/// The aliases to serve on
3131
#[arg(long, env = "TRUNK_SERVE_ALIAS")]
3232
pub alias: Option<Vec<String>>,
33+
/// Disable the lookup of addresses serving on during startup
34+
#[arg(long, env = "TRUNK_SERVE_DISABLE_ADDRESS_LOOKUP")]
35+
#[arg(default_missing_value="true", num_args=0..=1)]
36+
pub disable_address_lookup: Option<bool>,
3337
/// Open a browser tab once the initial build is complete [default: false]
3438
#[arg(long, env = "TRUNK_SERVE_OPEN")]
3539
#[arg(default_missing_value="true", num_args=0..=1)]
@@ -110,6 +114,7 @@ impl Serve {
110114
prefer_address_family,
111115
port,
112116
alias,
117+
disable_address_lookup,
113118
open,
114119
proxy:
115120
ProxyArgs {
@@ -136,6 +141,8 @@ impl Serve {
136141
config.serve.addresses = address.unwrap_or(config.serve.addresses);
137142
config.serve.port = port.unwrap_or(config.serve.port);
138143
config.serve.aliases = alias.unwrap_or(config.serve.aliases);
144+
config.serve.disable_address_lookup =
145+
disable_address_lookup.unwrap_or(config.serve.disable_address_lookup);
139146
config.serve.open = open.unwrap_or(config.serve.open);
140147
config.serve.prefer_address_family =
141148
prefer_address_family.or(config.serve.prefer_address_family);

src/config/models/serve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub struct Serve {
2020
pub addresses: Vec<IpAddr>,
2121
#[serde(default)]
2222
pub prefer_address_family: Option<AddressFamily>,
23+
/// Disable the reverse DNS lookup during startup
24+
#[serde(default)]
25+
pub disable_address_lookup: bool,
2326
/// The port to serve on [default: 8080]
2427
#[serde(default = "default::port")]
2528
pub port: u16,
@@ -90,6 +93,7 @@ impl Default for Serve {
9093
aliases: vec![],
9194
prefer_address_family: None,
9295
port: default::port(),
96+
disable_address_lookup: false,
9397
open: false,
9498
no_autoreload: false,
9599
headers: Default::default(),

src/config/rt/serve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct RtcServe {
3030
pub port: u16,
3131
/// The aliases to serve on.
3232
pub aliases: Vec<String>,
33+
/// Disable the DNS lookup during startup
34+
pub disable_address_lookup: bool,
3335
/// Open a browser tab once the initial build is complete.
3436
pub open: bool,
3537
/// Any proxies configured to run along with the server.
@@ -79,6 +81,7 @@ impl RtcServe {
7981
prefer_address_family,
8082
port,
8183
aliases,
84+
disable_address_lookup,
8285
open: _,
8386
// auto-reload is handle by the builder options
8487
no_autoreload: _,
@@ -110,6 +113,7 @@ impl RtcServe {
110113
addresses: build_address_list(prefer_address_family, addresses),
111114
port,
112115
aliases,
116+
disable_address_lookup,
113117
open,
114118
proxies: config.proxies.0,
115119
no_spa,

0 commit comments

Comments
 (0)