Make configurable with environment variables

This commit is contained in:
Shav Kinderlehrer 2024-04-05 22:48:54 -04:00
parent fd0a930245
commit dc56cda762
2 changed files with 8 additions and 9 deletions

View File

@ -36,7 +36,7 @@ pub async fn get_id(
if url::Url::parse(&it.url).is_ok() { if url::Url::parse(&it.url).is_ok() {
if show_request { if show_request {
return Html(format!( return Html(format!(
"<pre>{}/{} -> <a href={}>{}</a></pre>", "<pre>http://{}/{} -> <a href={}>{}</a></pre>",
state.host, it.id, it.url, it.url state.host, it.id, it.url, it.url
)) ))
.into_response(); .into_response();

View File

@ -11,8 +11,6 @@ use info_utils::prelude::*;
pub mod get; pub mod get;
pub mod post; pub mod post;
const LISTEN_ADDRESS: &'static str = "0.0.0.0:3000";
#[derive(Clone)] #[derive(Clone)]
pub struct ServerState { pub struct ServerState {
pub db_pool: Pool<Postgres>, pub db_pool: Pool<Postgres>,
@ -32,14 +30,15 @@ async fn main() -> eyre::Result<()> {
let db_pool = init_db().await?; let db_pool = init_db().await?;
let server_state = ServerState { let host = std::env::var("CHELA_HOST").unwrap_or("localhost".to_string());
db_pool, let server_state = ServerState { db_pool, host };
host: "trkt.in".to_string(),
}; 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 router = init_routes(server_state)?;
let listener = tokio::net::TcpListener::bind(LISTEN_ADDRESS).await?; let listener = tokio::net::TcpListener::bind(format!("{}:{}", address, port)).await?;
log!("Listening at {}", LISTEN_ADDRESS); log!("Listening at {}:{}", address, port);
axum::serve( axum::serve(
listener, listener,
router.into_make_service_with_connect_info::<SocketAddr>(), router.into_make_service_with_connect_info::<SocketAddr>(),