Skip to content

Commit cb691cc

Browse files
authored
feat: show actual addresses if 0.0.0.0 is used
1 parent a9e4954 commit cb691cc

File tree

5 files changed

+77
-48
lines changed

5 files changed

+77
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe
1111
- Added `data-loader-shim` to workers to create shim script.
1212
- Added tailwindcss support via `rel="tailwind-css"`.
1313
- Added support for `svg` files when using `rel="inline"`
14+
- Print all acessible addresses if `0.0.0.0` is used.
1415

1516
### changed
1617
- Updated gloo-worker example to use gloo-worker crate v2.1.

Cargo.lock

Lines changed: 38 additions & 46 deletions
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
@@ -30,6 +30,7 @@ envy = "0.4"
3030
flate2 = "1"
3131
fs_extra = "1"
3232
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
33+
local-ip-address = "0.5.1"
3334
nipper = "0.1"
3435
notify = "4"
3536
once_cell = "1"

src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub static BUILDING: Emoji<'_, '_> = Emoji("📦", "");
1818
pub static SUCCESS: Emoji<'_, '_> = Emoji("✅", "");
1919
pub static ERROR: Emoji<'_, '_> = Emoji("❌", "");
2020
pub static SERVER: Emoji<'_, '_> = Emoji("📡", "");
21+
pub static LOCAL: Emoji<'_, '_> = Emoji("🏠", "");
22+
pub static NETWORK: Emoji<'_, '_> = Emoji("💻", "");
2123

2224
static CWD: Lazy<PathBuf> =
2325
Lazy::new(|| std::env::current_dir().expect("error getting current dir"));

src/serve.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::net::{IpAddr, Ipv4Addr};
12
use std::path::PathBuf;
23
use std::sync::Arc;
34

@@ -13,7 +14,7 @@ use tokio::task::JoinHandle;
1314
use tower_http::services::{ServeDir, ServeFile};
1415
use tower_http::trace::TraceLayer;
1516

16-
use crate::common::SERVER;
17+
use crate::common::{LOCAL, NETWORK, SERVER};
1718
use crate::config::RtcServe;
1819
use crate::proxy::{ProxyHandlerHttp, ProxyHandlerWebSocket};
1920
use crate::watch::WatchSystem;
@@ -122,8 +123,40 @@ impl ServeSystem {
122123
.serve(router.into_make_service())
123124
.with_graceful_shutdown(shutdown_fut);
124125

126+
if addr.ip().is_unspecified() {
127+
let addresses = local_ip_address::list_afinet_netifas()
128+
.map(|addrs| {
129+
addrs
130+
.into_iter()
131+
.filter_map(|(_, ipaddr)| match ipaddr {
132+
IpAddr::V4(ip) if ip.is_private() || ip.is_loopback() => Some(ip),
133+
_ => None,
134+
})
135+
.collect::<Vec<_>>()
136+
})
137+
.unwrap_or_else(|_| vec![Ipv4Addr::LOCALHOST]);
138+
tracing::info!(
139+
"{} server listening at:\n{}",
140+
SERVER,
141+
addresses
142+
.iter()
143+
.map(|address| format!(
144+
" {} http://{}:{}",
145+
if address.is_loopback() {
146+
LOCAL
147+
} else {
148+
NETWORK
149+
},
150+
address,
151+
cfg.port
152+
))
153+
.collect::<Vec<_>>()
154+
.join("\n")
155+
);
156+
} else {
157+
tracing::info!("{} server listening at http://{}", SERVER, addr);
158+
}
125159
// Block this routine on the server's completion.
126-
tracing::info!("{} server listening at http://{}", SERVER, addr);
127160
Ok(tokio::spawn(async move {
128161
if let Err(err) = server.await {
129162
tracing::error!(error = ?err, "error from server task");

0 commit comments

Comments
 (0)