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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Embedded Svelte SPA static asset serving.
//!
//! Why: Single-binary deploys with no separate static-file dance. `build.rs`
//! runs the Vite build before compilation so the `ui/dist/` folder is always
//! populated and embedded.
//! What: `WebAssets` embed struct (via `rust_embed`), `static_handler` axum
//! fallback handler, and `serve_embedded` helper.
//! Test: `serves_index_html_fallback` in `web::tests`.
use ;
use RustEmbed;
/// Embedded UI assets produced by `pnpm build` in `ui/`.
///
/// Why: Single-binary deploys with no separate static-file dance. `build.rs`
/// runs the Vite build before compilation so this folder is always populated.
/// What: All files under `ui/dist/` are included in the binary.
/// Test: `serves_index_html_fallback` confirms the SPA shell loads.
// Monorepo migration: upstream trusty-memory put the Svelte UI at the repo
// root (`ui/dist/`), so the original path was `$CARGO_MANIFEST_DIR/../../ui/dist/`.
// In the trusty-tools monorepo we keep the UI inside the crate to avoid
// polluting the workspace root with per-crate asset directories.
pub ;
/// Serve any embedded asset; fall back to `index.html` for SPA routes.
///
/// Why: Hash-based routing lives client-side, but `/assets/foo.js` etc. must
/// resolve to the embedded file directly.
/// What: Looks up the request path under `WebAssets`; if absent, returns
/// `index.html`. Unknown paths under `/api/` return 404.
/// Test: `serves_index_html_fallback`, `unknown_api_returns_404`.
pub async
/// Look up an embedded asset by path and build a `Response` with the correct
/// `Content-Type`.
///
/// Why: Both the direct-path lookup and the SPA fallback share the same
/// response-building logic; extracting it prevents duplication.
/// What: Returns `None` when the path is not found in `WebAssets`; otherwise
/// wraps the bytes in a `Response` with `Content-Type` derived from the
/// file extension via `mime_guess`.
/// Test: Exercised via `static_handler` in `serves_index_html_fallback`.
pub