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
//! Embedded web dashboard for the Argentor gateway.
//!
//! Serves a single-page HTML dashboard that communicates with the control plane
//! REST API to display deployment, agent, and health information.
use axum::{
http::{header, StatusCode},
response::IntoResponse,
routing::get,
Router,
};
/// The dashboard HTML page, embedded at compile time.
const DASHBOARD_HTML: &str = include_str!("../dashboard.html");
/// The audit dashboard HTML page, embedded at compile time.
const AUDIT_DASHBOARD_HTML: &str = include_str!("../../../dashboard/audit.html");
/// Creates a router that serves the embedded dashboard.
///
/// Mounts `GET /dashboard` which returns the full SPA HTML page.
/// The dashboard itself fetches data from the control plane API endpoints
/// using client-side JavaScript.
pub fn dashboard_router() -> Router {
Router::new()
.route("/dashboard", get(dashboard_handler))
.route("/dashboard/audit", get(audit_dashboard_handler))
}
/// Serves the embedded HTML dashboard.
async fn dashboard_handler() -> impl IntoResponse {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
DASHBOARD_HTML,
)
}
/// Serves the embedded audit dashboard.
async fn audit_dashboard_handler() -> impl IntoResponse {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
AUDIT_DASHBOARD_HTML,
)
}