1
0
mirror of https://github.com/CCC-MF/bwhc-kafka-rest-proxy.git synced 2025-07-02 08:22:54 +00:00

feat: add config option for listen address and port

This commit is contained in:
2024-03-14 11:50:58 +01:00
parent 42b5189d32
commit 7b36255e2d
3 changed files with 19 additions and 2 deletions

View File

@ -27,4 +27,11 @@ pub struct Cli {
help = "bcrypt hashed Security Token"
)]
pub token: String,
#[arg(
long,
env = "APP_LISTEN",
default_value = "0.0.0.0:3000",
help = "Address and port for HTTP requests"
)]
pub listen: String,
}

View File

@ -58,8 +58,15 @@ async fn main() {
#[cfg(debug_assertions)]
let app = app.layer(TraceLayer::new_for_http());
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
match tokio::net::TcpListener::bind(&CONFIG.listen).await {
Ok(listener) => {
log::info!("Starting application listening on '{}'", CONFIG.listen);
if let Err(err) = axum::serve(listener, app).await {
log::error!("Error starting application: {}", err)
}
}
Err(err) => log::error!("Error listening on '{}': {}", CONFIG.listen, err),
};
}
async fn check_basic_auth(request: Request<Body>, next: Next) -> Response {