changeset 24:758a4f6c160f

Properly construct asset path
author Lewin Bormann <lbo@spheniscida.de>
date Tue, 12 Jul 2022 12:21:09 -0700
parents 1f33922b29f2
children 390a448dc8c7
files src/main.rs
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.rs	Tue Jul 12 12:02:47 2022 -0700
+++ b/src/main.rs	Tue Jul 12 12:21:09 2022 -0700
@@ -19,7 +19,7 @@
 
 use std::collections::HashMap;
 use std::net::IpAddr;
-use std::path::Path;
+use std::path::{Path, PathBuf};
 use std::time::Instant;
 
 #[cfg(feature = "sqlite")]
@@ -525,12 +525,24 @@
 fn rocketmain() -> _ {
     env_logger::init();
 
-    let r = rocket::build()
+    let r = rocket::build();
+    let cfg = r
+        .figment()
+        .extract::<CustomConfig>()
+        .expect("custom config");
+
+    let ap = Path::new(cfg.asset_path.as_str());
+    let ap = ap
+        .canonicalize()
+        .expect("absolute path to asset directory")
+        .to_path_buf();
+
+    let r = r
         .attach(ConfigDB::init())
         .attach(LogsDB::init())
         .attach(Template::fairing())
         .attach(rocket::fairing::AdHoc::config::<CustomConfig>())
-        .mount("/static", FileServer::from(relative!("assets/static")))
+        .mount("/static", FileServer::from(ap))
         .mount(
             "/",
             rocket::routes![