Skip to content

Commit

Permalink
feat: allow for user-defined host & port
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloanan committed Jul 31, 2024
1 parent 8832642 commit 9ae3a4b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ async fn main() {
.layer(permissive_cors)
.layer(TraceLayer::new_for_http());

let tcp_listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
let host = std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());

let tcp_listener = tokio::net::TcpListener::bind(format!("{host}:{port}"))
.await
.expect("Unable to bind to :3000");
info!("Listening on 0.0.0.0:3000");
.expect("Unable to bind to :{port}");
info!("Listening on {host}:{port}");

axum::serve(
tcp_listener,
Expand Down

0 comments on commit 9ae3a4b

Please sign in to comment.