aboutsummaryrefslogtreecommitdiff
path: root/server/src/assets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/assets.rs')
-rw-r--r--server/src/assets.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/server/src/assets.rs b/server/src/assets.rs
new file mode 100644
index 0000000..068bc0c
--- /dev/null
+++ b/server/src/assets.rs
@@ -0,0 +1,37 @@
+#[cfg(not(feature = "standalone"))]
+#[macro_export]
+macro_rules! s_file {
+ ($path: literal) => {
+ warp::fs::file($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) => {
+ warp::get().map(|| include_str!(concat!("../../", $path)))
+ };
+}
+
+#[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 {
+ DIR.get_file(t.as_str())
+ .map(|f| f.contents_utf8().unwrap())
+ .ok_or(warp::reject::not_found())
+ })
+ }};
+}