aboutsummaryrefslogtreecommitdiff
path: root/server/src/assets.rs
blob: 068bc0cde4a26d9d42e0f1042ba23be4e33fd91b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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())
        })
    }};
}