Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

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

4 changes: 4 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16>,
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Loading