From 8341ed16bac8aebc83db0e8fae4eb14a6dec9422 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 13 Apr 2025 14:57:30 +0200 Subject: fix include_dir problems --- server/src/assets.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/assets.rs b/server/src/assets.rs index 7195fbf..a80b6aa 100644 --- a/server/src/assets.rs +++ b/server/src/assets.rs @@ -26,7 +26,7 @@ macro_rules! s_file { ($path: literal, $content_type: literal) => { warp::any().map(|| { warp::reply::with_header( - include_bytes!(concat!("../../", $path)).to_vec(), + include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../", $path)).to_vec(), "content-type", $content_type, ) @@ -37,9 +37,19 @@ macro_rules! s_file { #[cfg(not(debug_assertions))] #[macro_export] macro_rules! s_asset_dir { - ($path:literal) => {{ + ("client-web/locale") => {{ use include_dir::{include_dir, Dir}; - const DIR: Dir = include_dir!(concat!("$CARGO_MANIFEST_DIR/../", $path)); + const DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/../client-web/locale"); + warp::path::tail().and_then(|t: warp::path::Tail| async move { + let path = t.as_str(); + DIR.get_file(path) + .map(|f| warp::reply::with_header(f.contents(), "content-type", "text/plain")) + .ok_or(warp::reject::not_found()) + }) + }}; + ("client-web/public/assets") => {{ + use include_dir::{include_dir, Dir}; + const DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/../client-web/public/assets"); warp::path::tail().and_then(|t: warp::path::Tail| async move { let path = t.as_str(); let content_type = match &path { @@ -47,7 +57,6 @@ macro_rules! s_asset_dir { _ if path.ends_with(".js") => "application/javascript", _ if path.ends_with(".css") => "text/css", _ if path.ends_with(".svg") => "image/svg+xml", - _ if path.ends_with(".ini") => "text/plain", _ => "application/octet-stream", }; DIR.get_file(path) -- cgit v1.2.3-70-g09d2