summaryrefslogtreecommitdiff
path: root/server/src/assets.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-04-04 11:15:03 +0200
committermetamuffin <metamuffin@disroot.org>2023-04-04 11:15:03 +0200
commit99d1ab55dfb1714d8f574060e618dc93c94f245c (patch)
treeb01f6ccb6b4060f120a71145fbbded0131c9430e /server/src/assets.rs
parent84587df365c61297e08d00f28317b452681a4b84 (diff)
parentfe36a0640f2e36baad1f08033f09b49bdd0f1062 (diff)
downloadkeks-meet-99d1ab55dfb1714d8f574060e618dc93c94f245c.tar
keks-meet-99d1ab55dfb1714d8f574060e618dc93c94f245c.tar.bz2
keks-meet-99d1ab55dfb1714d8f574060e618dc93c94f245c.tar.zst
Merge branch 'master' of codeberg.org:metamuffin/keks-meet
Diffstat (limited to 'server/src/assets.rs')
-rw-r--r--server/src/assets.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/src/assets.rs b/server/src/assets.rs
new file mode 100644
index 0000000..51b0025
--- /dev/null
+++ b/server/src/assets.rs
@@ -0,0 +1,51 @@
+#[cfg(not(feature = "standalone"))]
+#[macro_export]
+macro_rules! s_file {
+ ($path: literal, $content_type: literal) => {
+ warp::fs::file(concat!("../", $path))
+ };
+}
+
+#[cfg(not(feature = "standalone"))]
+#[macro_export]
+macro_rules! s_asset_dir {
+ () => {
+ warp::fs::dir("../client-web/public/assets")
+ };
+}
+
+#[cfg(feature = "standalone")]
+#[macro_export]
+macro_rules! s_file {
+ ($path: literal, $content_type: literal) => {
+ warp::any().map(|| {
+ warp::reply::with_header(
+ include_str!(concat!("../../", $path)),
+ "content-type",
+ $content_type,
+ )
+ })
+ };
+}
+
+#[cfg(feature = "standalone")]
+#[macro_export]
+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 {
+ 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",
+ _ if path.ends_with(".svg") => "image/svg+xml",
+ _ => "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())
+ })
+ }};
+}