diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 12 |
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(); } |
