Skip to content

Commit

Permalink
feat: add config option for listen address and port
Browse files Browse the repository at this point in the history
  • Loading branch information
pcvolkmer committed Mar 14, 2024
1 parent 42b5189 commit 7b36255
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ Options:
Kafka Topic [env: APP_KAFKA_TOPIC=] [default: etl-processor_input]
--token <TOKEN>
bcrypt hashed Security Token [env: APP_SECURITY_TOKEN=]
--listen <LISTEN>
Address and port for HTTP requests [env: APP_LISTEN=] [default: 0.0.0.0:3000]
```

Die Anwendung lässt sich auch mit Umgebungsvariablen konfigurieren.

* `APP_KAFKA_SERVERS`: Zu verwendende Kafka-Bootstrap-Server als kommagetrennte Liste
* `APP_KAFKA_TOPIC`: Zu verwendendes Topic zum Warten auf neue Anfragen. Standardwert: `etl-processor_input`
* `APP_SECURITY_TOKEN`: Verpflichtende Angabe es Tokens als *bcrypt*-Hash
* `APP_LISTEN`: Adresse und Port für eingehende HTTP-Requests. Standardwert: `0.0.0.0:3000` - Port `3000` auf allen Adressen

## HTTP-Requests

Expand Down
7 changes: 7 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7b36255

Please sign in to comment.