Skip to content

Commit 2126b13

Browse files
committed
feat(server): log local network and host addresses
1 parent 4a6ce9c commit 2126b13

File tree

2 files changed

+13
-137
lines changed

2 files changed

+13
-137
lines changed

Cargo.lock

Lines changed: 1 addition & 133 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/http-server/src/server/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod config;
22
pub mod plugin;
33

44
use std::convert::Infallible;
5-
use std::net::SocketAddr;
5+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
66
use std::path::PathBuf;
77
use std::str::FromStr;
88
use std::sync::Arc;
@@ -14,6 +14,7 @@ use hyper::server::conn::http1;
1414
use hyper::{Method, Request, Response};
1515
use hyper_util::rt::TokioIo;
1616
use hyper_util::service::TowerToHyperService;
17+
use local_ip_address::local_ip;
1718
use tokio::net::TcpListener;
1819
use tokio::runtime::Runtime;
1920
use tower::ServiceBuilder;
@@ -22,6 +23,8 @@ use tower_http::cors::{Any, CorsLayer};
2223
use self::config::Config;
2324
use self::plugin::ExternalFunctions;
2425

26+
const ALL_INTERFACES_IPV4: Ipv4Addr = Ipv4Addr::new(0, 0, 0, 0);
27+
2528
pub struct Server {
2629
config: Config,
2730
}
@@ -39,6 +42,14 @@ impl Server {
3942
let config = PathBuf::from_str("./config.toml")?;
4043
let handle = Arc::new(rt.handle().to_owned());
4144

45+
println!("Listening on http://{}", addr);
46+
47+
if matches!(addr.ip(), IpAddr::V4(ALL_INTERFACES_IPV4)) {
48+
if let Ok(local_ip) = local_ip() {
49+
println!("Local Network on http://{}", local_ip);
50+
}
51+
}
52+
4253
unsafe {
4354
functions
4455
.load(Arc::clone(&handle), config, plugin_library)
@@ -49,9 +60,6 @@ impl Server {
4960
let (stream, _) = listener.accept().await?;
5061
let io = TokioIo::new(stream);
5162
let functions = Arc::clone(&functions);
52-
53-
println!("{:#?}", self.config);
54-
5563
let cors = if self.config.cors {
5664
Some(
5765
CorsLayer::new()

0 commit comments

Comments
 (0)