From dc56cda762703f07ad8d9ff57fbc36713c4dbaf7 Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Fri, 5 Apr 2024 22:48:54 -0400 Subject: [PATCH] Make configurable with environment variables --- src/get.rs | 2 +- src/main.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/get.rs b/src/get.rs index 9507125..eb2eb05 100644 --- a/src/get.rs +++ b/src/get.rs @@ -36,7 +36,7 @@ pub async fn get_id( if url::Url::parse(&it.url).is_ok() { if show_request { return Html(format!( - "
{}/{} -> {}
", + "
http://{}/{} -> {}
", state.host, it.id, it.url, it.url )) .into_response(); diff --git a/src/main.rs b/src/main.rs index 51dd969..57c6430 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,6 @@ use info_utils::prelude::*; pub mod get; pub mod post; -const LISTEN_ADDRESS: &'static str = "0.0.0.0:3000"; - #[derive(Clone)] pub struct ServerState { pub db_pool: Pool, @@ -32,14 +30,15 @@ async fn main() -> eyre::Result<()> { let db_pool = init_db().await?; - let server_state = ServerState { - db_pool, - host: "trkt.in".to_string(), - }; + let host = std::env::var("CHELA_HOST").unwrap_or("localhost".to_string()); + let server_state = ServerState { db_pool, host }; + + let address = std::env::var("LISTEN_ADDRESS").unwrap_or("0.0.0.0".to_string()); + let port = std::env::var("LISTEN_PORT").unwrap_or("3000".to_string()); let router = init_routes(server_state)?; - let listener = tokio::net::TcpListener::bind(LISTEN_ADDRESS).await?; - log!("Listening at {}", LISTEN_ADDRESS); + let listener = tokio::net::TcpListener::bind(format!("{}:{}", address, port)).await?; + log!("Listening at {}:{}", address, port); axum::serve( listener, router.into_make_service_with_connect_info::(),