From 39adc3fb62d5783e08ac57aa8784afebbb50e067 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Wed, 25 Sep 2024 13:14:14 +0200 Subject: [PATCH] feat: Make the bind address configurable --- config.toml | 1 + src/config.rs | 1 + src/handlers.rs | 1 + src/main.rs | 4 +++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index 67e263f..ee12a78 100644 --- a/config.toml +++ b/config.toml @@ -1,2 +1,3 @@ [settings] base_directory = "/strg/drw" +bind_address = "127.0.0.1:3012" diff --git a/src/config.rs b/src/config.rs index bd12240..2cbec46 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,7 @@ pub struct Config { #[derive(Deserialize)] pub struct Settings { pub base_directory: String, + pub bind_address: String, } pub fn read_config() -> Result> { diff --git a/src/handlers.rs b/src/handlers.rs index 8bbf2fa..7f11995 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -15,6 +15,7 @@ pub async fn list_files( let template = ListTemplate { files: files.to_vec(), }; + HtmlTemplate(template) } diff --git a/src/main.rs b/src/main.rs index f12b1fb..2bdec74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,9 @@ async fn main() { ) .with_state(files); - let listener = TcpListener::bind("127.0.0.1:3004").await.unwrap(); + let listener = TcpListener::bind(config.settings.bind_address) + .await + .unwrap(); println!("Listening on {}", listener.local_addr().unwrap()); axum::serve(listener, app).await.unwrap();