From 53b1f4f2445f4702021100e91335426b014ca689 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Fri, 27 Dec 2024 04:49:09 -0800 Subject: [PATCH] feat: smarter paths --- src/lib.rs | 13 ++++++++++++- src/main.rs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3394a4e..f5edf7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,4 +10,15 @@ pub use views::*; use std::{path::PathBuf, sync::LazyLock}; -pub static CACHE_DIR: LazyLock = LazyLock::new(|| PathBuf::from("/var/lib/nyazoom/cache")); +pub static CACHE_DIR: LazyLock = LazyLock::new(|| { + std::env::var("CACHE_DIR") + .ok() + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from("/var/lib/nyazoom/cache")) +}); +pub static DIST_DIR: LazyLock = LazyLock::new(|| { + std::env::var("DIST_DIR") + .ok() + .map(PathBuf::from) + .unwrap_or_else(|| PathBuf::from("./dist")) +}); diff --git a/src/main.rs b/src/main.rs index 91d0482..20271de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ async fn main() -> io::Result<()> { .nest("/records", get_records_router()) .nest("/link", get_link_router()) .with_state(state) - .fallback_service(ServeDir::new("dist")) + .fallback_service(ServeDir::new(&*DIST_DIR)) .layer(TraceLayer::new_for_http()) .layer(middleware::from_fn(log_source));