Add option to add port to listen on

This commit is contained in:
clerie 2024-07-14 20:21:07 +02:00
parent 9d0f35db70
commit c3c5ff4ebe
2 changed files with 26 additions and 2 deletions

View File

@ -7,5 +7,5 @@ There is also a Map: <https://www.berlinerbaeder.de/baeder/sommerbaeder-auslastu
## Run ## Run
``` ```
berlinerbaeder-exporter berlinerbaeder-exporter --listen "[::]:1234"
``` ```

View File

@ -29,11 +29,35 @@ struct TrafficDataItem {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let mut args = std::env::args();
let _name = args.next().unwrap();
let mut listen = String::from("[::]:3000");
loop {
let arg = if let Some(arg) = args.next() {
arg
} else {
break;
};
match arg.as_str() {
"--listen" => {
listen = args.next().unwrap();
}
unknown => {
println!("unknown option: {}", unknown);
std::process::exit(1)
}
}
}
let app = Router::new() let app = Router::new()
.route("/", get(route_index)) .route("/", get(route_index))
.route("/metrics", get(route_metrics)); .route("/metrics", get(route_metrics));
let listener = tokio::net::TcpListener::bind("[::]:3000").await.unwrap(); let listener = tokio::net::TcpListener::bind(listen).await.unwrap();
println!("Server listening on: http://{}", listener.local_addr().unwrap()); println!("Server listening on: http://{}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap(); axum::serve(listener, app).await.unwrap();