* Add --bind option

* Changed default bind address to localhost
* Fix wrong log text about binding address
This commit is contained in:
FixFromDarkness 2022-07-07 19:45:31 +03:00
parent 73ec59ccda
commit cc2dd1e1fe
2 changed files with 9 additions and 4 deletions

View file

@ -1,3 +1,4 @@
use std::net::IpAddr;
use clap::Parser; use clap::Parser;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -36,7 +37,10 @@ pub struct Args {
pub highlightsyntax: bool, pub highlightsyntax: bool,
#[clap(short, long, default_value_t = 8080)] #[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)] #[clap(long)]
pub private: bool, pub private: bool,
@ -55,4 +59,4 @@ pub struct Args {
#[clap(long)] #[clap(long)]
pub wide: bool, pub wide: bool,
} }

View file

@ -58,7 +58,8 @@ async fn main() -> std::io::Result<()> {
.init(); .init();
log::info!( log::info!(
"MicroBin starting on http://127.0.0.1:{}", "MicroBin starting on http://{}:{}",
ARGS.bind.to_string(),
ARGS.port.to_string() ARGS.port.to_string()
); );
@ -97,7 +98,7 @@ async fn main() -> std::io::Result<()> {
HttpAuthentication::basic(util::auth::auth_validator), 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) .workers(ARGS.threads as usize)
.run() .run()
.await .await