Skip to content

Commit 7dfa096

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

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ The server is configured with command-line options. See
7171
`taskchampion-sync-server --help` for full details.
7272

7373
The `--data-dir` option specifies where the server should store its data, and
74-
`--port` gives the port on which the HTTP server runs.
74+
`--port` gives the port on which the HTTP server runs. You can also specify the
75+
listen address with `--listen`. The default listen address ist localhost, so if
76+
you do not use a reverse proxy or have custom container based deployment you
77+
probably have to change this.
7578

7679
By default, the server allows all client IDs. To limit the accepted client IDs,
7780
such as when running a personal server, use `--allow-client-id <client-id>`.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ services:
5656
volume:
5757
nocopy: true
5858
subpath: tss
59-
command: --data-dir /tss/taskchampion-sync-server --port 8080
59+
command: --data-dir /tss/taskchampion-sync-server --port 8080 --listen 0.0.0.0
6060
environment:
6161
- RUST_LOG=info
6262
depends_on:

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

Lines changed: 13 additions & 5 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,15 +83,16 @@ 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()
87-
.await?;
91+
});
92+
for listen_address in matches.get_many::<String>("listen").unwrap() {
93+
http_server = http_server.bind((listen_address.as_str(), port))?
94+
}
95+
http_server.run().await?;
8896
Ok(())
8997
}
9098

0 commit comments

Comments
 (0)