summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorSerguey Parkhomovsky <xindigo@gmail.com>2026-03-21 11:29:28 -0700
committerSerguey Parkhomovsky <xindigo@gmail.com>2026-03-21 11:31:00 -0700
commite755cc4b45356b0484eb9254b4a0647cdca1591e (patch)
tree32785f2740607cbec5a998619b24f0c41cae7d85 /src/main.rs
parent50a45092eab7f7f6c1f701bffe40226dcb6eeaf9 (diff)
Add bind arg and better error handling
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 187c0fe..5337fc3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,6 +19,10 @@ struct Args {
/// Path to the configuration file
#[arg(long, default_value = "config.toml")]
config: String,
+
+ /// Address to bind the HTTP server to
+ #[arg(long, default_value = "0.0.0.0:3000")]
+ bind: String,
}
#[tokio::main]
@@ -26,7 +30,8 @@ async fn main() {
tracing_subscriber::fmt::init();
let args = Args::parse();
- let content = fs::read_to_string(&args.config).expect("Couldn't read config file");
+ let content = fs::read_to_string(&args.config)
+ .unwrap_or_else(|e| panic!("Failed to read '{}': {}", args.config, e));
let config = Config::load(&content);
let state: StateMap = Arc::new(Mutex::new(HashMap::new()));
let mut tasks = JoinSet::new();
@@ -80,7 +85,10 @@ async fn main() {
let app = Router::new().route("/", get(root)).with_state(state);
- let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
+ let listener = tokio::net::TcpListener::bind(&args.bind)
+ .await
+ .unwrap_or_else(|e| panic!("Failed to bind to '{}': {}", args.bind, e));
+ println!("Listening on {}", args.bind);
axum::serve(listener, app).await.unwrap();
}