feat: Make the bind address configurable

This commit is contained in:
Dendy 2024-09-25 13:14:14 +02:00
parent 2c27dc3bf6
commit 39adc3fb62
4 changed files with 6 additions and 1 deletions

View File

@ -1,2 +1,3 @@
[settings]
base_directory = "/strg/drw"
bind_address = "127.0.0.1:3012"

View File

@ -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<Config, Box<dyn std::error::Error>> {

View File

@ -15,6 +15,7 @@ pub async fn list_files(
let template = ListTemplate {
files: files.to_vec(),
};
HtmlTemplate(template)
}

View File

@ -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();