From 472a10e74df2b0d5f15967408fa1e88251767a19 Mon Sep 17 00:00:00 2001 From: serxoz Date: Fri, 20 Jan 2023 21:39:02 +0100 Subject: [PATCH] configurable con variables de entorno --- README.md | 5 +++++ src/main.rs | 2 +- src/views/astronaves.rs | 3 ++- src/views/personajes.rs | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d92b0c6..b942af7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # Generadores para Into the Kosmos La idea es tener en una web los generadores de personajes, naves, monstruos, etc... + +## Run +``` +TEMPLATES="templates" PORT="3007" cargo run +``` diff --git a/src/main.rs b/src/main.rs index c9a9fcf..a93b62b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ async fn main() { .route("/astronaves", get(genera_astronave)); // executase con hyper a través de axum::Server - let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); + let addr = SocketAddr::from(([127, 0, 0, 1], into_the_kosmos_generador::env_listen_port())); tracing::debug!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service()) diff --git a/src/views/astronaves.rs b/src/views/astronaves.rs index f64ff46..f856248 100644 --- a/src/views/astronaves.rs +++ b/src/views/astronaves.rs @@ -52,7 +52,8 @@ pub async fn genera_astronave() -> Html { ], }; - let template = fs::read_to_string("templates/astronave.html").unwrap(); + let path = format!("{}/astronave.html", into_the_kosmos_generador::env_templates_dir()); + let template = fs::read_to_string(path).unwrap(); let r = render!(&template, astronave => ast); Html(r) } diff --git a/src/views/personajes.rs b/src/views/personajes.rs index 013975b..63448bd 100644 --- a/src/views/personajes.rs +++ b/src/views/personajes.rs @@ -35,7 +35,8 @@ pub async fn genera_pj() -> Html { equipo: trasf.equipo, }; - let template = fs::read_to_string("templates/personaje.html").unwrap(); + let path = format!("{}/personaje.html", into_the_kosmos_generador::env_templates_dir()); + let template = fs::read_to_string(path).unwrap(); let r = render!(&template, personaje => pj); Html(r) }