Skip to content

Commit fb549ac

Browse files
committed
Allow to specify the listen address on the cli
1 parent b27cb36 commit fb549ac

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

server/src/bin/taskchampion-sync-server.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ fn command() -> Command {
2626
.value_parser(value_parser!(u16))
2727
.default_value("8080"),
2828
)
29+
.arg(
30+
arg!(-l --listen <ADDRESS>)
31+
.help("Address on which to listen on. Can be an IP Address or a DNS name. Can be repeated.")
32+
.value_parser(ValueParser::string())
33+
.default_value("localhost")
34+
.action(ArgAction::Append),
35+
)
2936
.arg(
3037
arg!(-d --"data-dir" <DIR> "Directory in which to store data")
3138
.value_parser(ValueParser::os_string())
@@ -76,14 +83,17 @@ async fn main() -> anyhow::Result<()> {
7683
let server = WebServer::new(config, client_id_allowlist, SqliteStorage::new(data_dir)?);
7784

7885
log::info!("Serving on port {}", port);
79-
HttpServer::new(move || {
86+
let mut http_server = HttpServer::new(move || {
8087
App::new()
8188
.wrap(ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, print_error))
8289
.wrap(Logger::default())
8390
.configure(|cfg| server.config(cfg))
84-
})
85-
.bind(("0.0.0.0", port))?
86-
.run()
91+
});
92+
for listen_address in matches.get_many::<String>("listen").unwrap() {
93+
94+
http_server = http_server.bind((listen_address.as_str(), port))?
95+
}
96+
http_server.run()
8797
.await?;
8898
Ok(())
8999
}

0 commit comments

Comments
 (0)