summaryrefslogtreecommitdiff
path: root/server/src/assets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/assets.rs')
-rw-r--r--server/src/assets.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/server/src/assets.rs b/server/src/assets.rs
index 068bc0c..bdd7ef9 100644
--- a/server/src/assets.rs
+++ b/server/src/assets.rs
@@ -1,7 +1,7 @@
#[cfg(not(feature = "standalone"))]
#[macro_export]
macro_rules! s_file {
- ($path: literal) => {
+ ($path: literal, $content_type: literal) => {
warp::fs::file($path)
};
}
@@ -17,8 +17,14 @@ macro_rules! s_asset_dir {
#[cfg(feature = "standalone")]
#[macro_export]
macro_rules! s_file {
- ($path: literal) => {
- warp::get().map(|| include_str!(concat!("../../", $path)))
+ ($path: literal, $content_type: literal) => {
+ warp::any().map(|| {
+ warp::reply::with_header(
+ include_str!(concat!("../../", $path)),
+ "content-type",
+ $content_type,
+ )
+ })
};
}
@@ -29,8 +35,15 @@ macro_rules! s_asset_dir {
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 {
- DIR.get_file(t.as_str())
- .map(|f| f.contents_utf8().unwrap())
+ let path = t.as_str();
+ let content_type = match &path {
+ _ if path.ends_with(".wasm") => "application/wasm",
+ _ if path.ends_with(".js") => "application/javascript",
+ _ if path.ends_with(".css") => "text/css",
+ _ => "application/octet-stream",
+ };
+ DIR.get_file(path)
+ .map(|f| warp::reply::with_header(f.contents(), "content-type", content_type))
.ok_or(warp::reject::not_found())
})
}};