blob: bdd7ef9129c0983b97b5362f10401159af999dd5 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#[cfg(not(feature = "standalone"))]
#[macro_export]
macro_rules! s_file {
($path: literal, $content_type: 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, $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",
_ => "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())
})
}};
}
|