From d50e8f5887ae520fcbc13ffec13d26f86e370ad3 Mon Sep 17 00:00:00 2001 From: blek Date: Fri, 29 Sep 2023 20:57:53 +1000 Subject: [PATCH] load the listen address from .env --- filed/.env | 3 ++- filed/src/env.rs | 6 ++++-- filed/src/main.rs | 2 +- filed/src/web/mod.rs | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/filed/.env b/filed/.env index 59a0a1c..518b22d 100644 --- a/filed/.env +++ b/filed/.env @@ -1 +1,2 @@ -APP_LOGGING=true \ No newline at end of file +APP_LOGGING=true +APP_HOST=0.0.0.0:8080 diff --git a/filed/src/env.rs b/filed/src/env.rs index f270a07..d5cf79a 100644 --- a/filed/src/env.rs +++ b/filed/src/env.rs @@ -3,10 +3,11 @@ This file provides the `loadenv` function that will do just that. */ -use std::env::var; +use std::{env::var, net::SocketAddr}; pub struct Env { - pub logging: bool + pub logging: bool, + pub listen: SocketAddr } fn get_var, O: From>(name: T) -> Result { @@ -22,6 +23,7 @@ pub fn loadenv() -> Result> { Ok( Env { logging: get_var::<&str, String>("APP_LOGGING")?.to_lowercase() == "true", + listen: get_var::<&str, String>("APP_HOST")?.parse::().unwrap() } ) } \ No newline at end of file diff --git a/filed/src/main.rs b/filed/src/main.rs index 60a5af0..2e253dd 100644 --- a/filed/src/main.rs +++ b/filed/src/main.rs @@ -22,5 +22,5 @@ async fn main() { femme::with_level(femme::LevelFilter::Off); } - web::serve().await; + web::serve(envy).await; } diff --git a/filed/src/web/mod.rs b/filed/src/web/mod.rs index a5de9c4..f59e8e3 100644 --- a/filed/src/web/mod.rs +++ b/filed/src/web/mod.rs @@ -2,14 +2,16 @@ web - The part of filed that handles everything related to HTTP */ +use crate::env::Env; + mod pages; /* Serve the HTTP server */ -pub async fn serve() { +pub async fn serve(env: Env) { - log::info!("Listening on 0.0.0.0:80"); + log::info!("Listening on {}", env.listen.to_string()); - warp::serve(pages::get_routes()).run(([0,0,0,0], 80)).await; + warp::serve(pages::get_routes()).run(env.listen).await; } \ No newline at end of file