1
0

add option to allow listening on localhost

This commit is contained in:
Rokas Puzonas 2024-06-30 18:03:29 +03:00
parent 4d650c1566
commit 82b6d785de

View File

@ -36,6 +36,10 @@ async fn main() -> anyhow::Result<()> {
.value_parser(value_parser!(u16)) .value_parser(value_parser!(u16))
.default_value(defaults.port.to_string()), .default_value(defaults.port.to_string()),
) )
.arg(
arg!(--host <ADDRESS> "On what address to host server")
.default_value("localhost"),
)
.arg( .arg(
arg!(--"snapshot-versions" <NUM> "Target number of versions between snapshots") arg!(--"snapshot-versions" <NUM> "Target number of versions between snapshots")
.value_parser(value_parser!(u32)) .value_parser(value_parser!(u32))
@ -75,6 +79,7 @@ async fn main() -> anyhow::Result<()> {
} }
}, },
None => { None => {
let host: &String = matches.get_one("host").unwrap();
let port: u16 = *matches.get_one("port").unwrap(); let port: u16 = *matches.get_one("port").unwrap();
let snapshot_versions: u32 = *matches.get_one("snapshot-versions").unwrap(); let snapshot_versions: u32 = *matches.get_one("snapshot-versions").unwrap();
let snapshot_days: i64 = *matches.get_one("snapshot-days").unwrap(); let snapshot_days: i64 = *matches.get_one("snapshot-days").unwrap();
@ -85,13 +90,13 @@ async fn main() -> anyhow::Result<()> {
let server = Server::new(config, Box::new(storage)); let server = Server::new(config, Box::new(storage));
log::warn!("Serving on port {}", port); log::info!("Serving on {}:{}", host, port);
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
.wrap(Logger::default()) .wrap(Logger::default())
.configure(|cfg| server.config(cfg)) .configure(|cfg| server.config(cfg))
}) })
.bind(format!("0.0.0.0:{}", port))? .bind(format!("{}:{}", host, port))?
.run() .run()
.await?; .await?;
}, },