From cc2dd1e1fe3fe3db5fafa13e90e51b26e184bc24 Mon Sep 17 00:00:00 2001 From: FixFromDarkness Date: Thu, 7 Jul 2022 19:45:31 +0300 Subject: [PATCH 1/2] * Add --bind option * Changed default bind address to localhost * Fix wrong log text about binding address --- src/args.rs | 8 ++++++-- src/main.rs | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/args.rs b/src/args.rs index 15546df..e36eb08 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,3 +1,4 @@ +use std::net::IpAddr; use clap::Parser; use lazy_static::lazy_static; @@ -36,7 +37,10 @@ pub struct Args { pub highlightsyntax: bool, #[clap(short, long, default_value_t = 8080)] - pub port: u32, + pub port: u16, + + #[clap(short, long, default_value_t = IpAddr::from([127, 0, 0, 1]))] + pub bind: IpAddr, #[clap(long)] pub private: bool, @@ -55,4 +59,4 @@ pub struct Args { #[clap(long)] pub wide: bool, -} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9f12d4b..1c18a31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,8 @@ async fn main() -> std::io::Result<()> { .init(); log::info!( - "MicroBin starting on http://127.0.0.1:{}", + "MicroBin starting on http://{}:{}", + ARGS.bind.to_string(), ARGS.port.to_string() ); @@ -97,7 +98,7 @@ async fn main() -> std::io::Result<()> { HttpAuthentication::basic(util::auth::auth_validator), )) }) - .bind(format!("0.0.0.0:{}", ARGS.port.to_string()))? + .bind((ARGS.bind, ARGS.port))? .workers(ARGS.threads as usize) .run() .await From fec933c5ecc3b007377f2c40d7841e35363725dc Mon Sep 17 00:00:00 2001 From: FixFromDarkness Date: Thu, 7 Jul 2022 20:08:29 +0300 Subject: [PATCH 2/2] * Revert default address to 0.0.0.0 due to docker usage & compatibility * Add --bind option to readme & change some examples --- README.MD | 11 +++++++++-- src/args.rs | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index d9ea214..f303a05 100644 --- a/README.MD +++ b/README.MD @@ -105,11 +105,11 @@ Remember, MicroBin will create your database and file storage wherever you execu `cd ~/microbin/` -`microbin --port 8080 --highlightsyntax --editable` +`microbin --highlightsyntax --editable` ### Building MicroBin -Simply clone the repository, build it with `cargo build --release` and run the `microbin` executable in the created `target/release/` directory. It will start on port 8080. You can change the port with `-p` or `--port` CL arguments. For other arguments see [the Wiki](https://github.com/szabodanika/microbin/wiki). +Simply clone the repository, build it with `cargo build --release` and run the `microbin` executable in the created `target/release/` directory. It will start listening on 0.0.0.0:8080. You can change the port or bind address with CL arguments `-p (--port)` or `-b (--bind)` respectively . For other arguments see [the Wiki](https://github.com/szabodanika/microbin/wiki). ``` git clone https://github.com/szabodanika/microbin.git @@ -283,6 +283,13 @@ Default value: 8080 Sets the port for the server will be listening on. + +### -b, --bind [ADDRESS] + +Default value: 0.0.0.0 + +Sets the bind address for the server will be listening on. Both ipv4 and ipv6 are supported. + ### --private Enables private pastas. Adds a new checkbox to make your pasta private, which then won't show up on the pastalist page. With the URL to your pasta, it will still be accessible. diff --git a/src/args.rs b/src/args.rs index e36eb08..4a97f3b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -39,7 +39,7 @@ pub struct Args { #[clap(short, long, default_value_t = 8080)] pub port: u16, - #[clap(short, long, default_value_t = IpAddr::from([127, 0, 0, 1]))] + #[clap(short, long, default_value_t = IpAddr::from([0, 0, 0, 0]))] pub bind: IpAddr, #[clap(long)]