From c22d888bfd99e25fd2549d8f40c51ff510975227 Mon Sep 17 00:00:00 2001 From: vimlinuz Date: Mon, 18 May 2026 22:39:14 +0545 Subject: [PATCH 1/4] refactored: added a new flag to bind to all interface --- src/args.rs | 4 ++++ src/main.rs | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/args.rs b/src/args.rs index 88d687d..d379ae9 100644 --- a/src/args.rs +++ b/src/args.rs @@ -17,6 +17,10 @@ pub struct MdwatchArgs { #[clap(short, long, default_value = "127.0.0.1")] pub ip: String, + /// Bind to all interfaces (0.0.0.0) + #[clap(long, conflicts_with = "ip")] + pub public: bool, + /// Port number to serve on (If not provided, a random port will be used) #[clap(short, long)] pub port: Option, diff --git a/src/main.rs b/src/main.rs index eb42f16..6c8daaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,7 +146,12 @@ async fn main() -> std::io::Result<()> { let args = MdwatchArgs::parse(); let file = args.file; - let mut ip = args.ip; + let ip = if args.public { + String::from("0.0.0.0") + } else { + args.ip + }; + let port = args.port.unwrap_or_else(get_random_port); // Resolve the parent directory of the markdown file for serving local images @@ -166,12 +171,14 @@ async fn main() -> std::io::Result<()> { if ip == "0.0.0.0" { eprintln!(" Warning: Binding to 0.0.0.0 exposes your server to the entire network!"); eprintln!(" Make sure you trust your network or firewall settings."); - ip = get_local_ip().unwrap_or(String::from("0.0.0.0")); + let local_ip = get_local_ip().unwrap_or(String::from("0.0.0.0")); + println!("Server running at:"); + println!(" - http://{}:{}/", local_ip, port); + } else { + println!("Server running at:"); + println!(" - http://{}:{}/", ip, port); } - println!("Server running at:"); - println!(" - http://{}:{}/", ip, port); - match HttpServer::new(move || { App::new() .route("/ws", web::get().to(ws_handler)) @@ -183,7 +190,7 @@ async fn main() -> std::io::Result<()> { .bind(format!("{}:{}", ip, port)) { Ok(server) => { - if let Err(e) = webbrowser::open(&format!("http://{}:{}/", ip, port)) { + if let Err(e) = webbrowser::open(&format!("http://localhost:{}/", port)) { eprintln!("Failed to open browser: {e}"); } server.run().await From dfb78ff8bb50e3a4c0ae324a4fcee6bc0527b5e7 Mon Sep 17 00:00:00 2001 From: vimlinuz Date: Mon, 18 May 2026 22:39:32 +0545 Subject: [PATCH 2/4] docs: update docs with latest args --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ba7aeef..de75686 100644 --- a/README.md +++ b/README.md @@ -185,13 +185,14 @@ cargo uninstall mdwatch Run the tool with the required and optional arguments: ```bash -mdwatch README.md [--ip 127.0.0.1] [--port 3000] - +mdwatch README.md [--ip 127.0.0.1] [--public] [--port 3000] ``` - `file`: Path to the Markdown file to preview (required) -- `--ip`: IP address to bind the server to (default: 127.0.0.1) +- `--ip`: IP address to bind the server to (default: 127.0.0.1). Cannot be used with `--public`. + +- `--public`: Bind to all interfaces (0.0.0.0). Use this to make the preview reachable from other devices on your network. - `--port`: Port number for the server (If not provided, a random port will be used) @@ -206,7 +207,7 @@ mdwatch README.md [--ip 127.0.0.1] [--port 3000] # Example ```bash -mdwatch notes.md --ip 0.0.0.0 --port 8080 +mdwatch notes.md --public --port 8080 ``` This will serve the Markdown file accessible on all network interfaces and open the preview at From f790a3f0b200635c4a566aa66d47a522a94cddb1 Mon Sep 17 00:00:00 2001 From: vimlinuz Date: Mon, 18 May 2026 22:40:22 +0545 Subject: [PATCH 3/4] update(deps): update flake --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index ec46f64..63134f7 100644 --- a/flake.lock +++ b/flake.lock @@ -59,11 +59,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1778443072, - "narHash": "sha256-zi7/fsqM/kFdNuED//4WOCUtezGtKKqRNORjMvfwjnA=", + "lastModified": 1778869304, + "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "da5ad661ba4e5ef59ba743f0d112cbc30e474f32", + "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", "type": "github" }, "original": { From 39dc8e3311056bef282eee5577ee228bdef4f154 Mon Sep 17 00:00:00 2001 From: vimlinuz Date: Mon, 18 May 2026 22:46:51 +0545 Subject: [PATCH 4/4] fix: open browser on bound ip --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6c8daaf..259cb30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -190,7 +190,7 @@ async fn main() -> std::io::Result<()> { .bind(format!("{}:{}", ip, port)) { Ok(server) => { - if let Err(e) = webbrowser::open(&format!("http://localhost:{}/", port)) { + if let Err(e) = webbrowser::open(&format!("http://{}:{}/", ip, port)) { eprintln!("Failed to open browser: {e}"); } server.run().await