diff options
author | Shav Kinderlehrer <[email protected]> | 2024-04-05 22:48:54 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2024-04-05 22:48:54 -0400 |
commit | dc56cda762703f07ad8d9ff57fbc36713c4dbaf7 (patch) | |
tree | 705832cf81ee6dabd4241938ffaa02d802c5f6ef | |
parent | fd0a9302450a4f5e0108d03a95db1601c00b5e4c (diff) | |
download | chela-dc56cda762703f07ad8d9ff57fbc36713c4dbaf7.tar.gz chela-dc56cda762703f07ad8d9ff57fbc36713c4dbaf7.zip |
Make configurable with environment variables
-rw-r--r-- | src/get.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 15 |
2 files changed, 8 insertions, 9 deletions
@@ -36,7 +36,7 @@ pub async fn get_id( if url::Url::parse(&it.url).is_ok() { if show_request { return Html(format!( - "<pre>{}/{} -> <a href={}>{}</a></pre>", + "<pre>http://{}/{} -> <a href={}>{}</a></pre>", 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<Postgres>, @@ -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::<SocketAddr>(), |