#[cfg(feature = "server")]
pub mod api_v1;
#[cfg(feature = "server")]
use axum::Router;
#[cfg(feature = "server")]
use axum::http::{StatusCode, header};
#[cfg(feature = "server")]
use axum::response::IntoResponse;
#[cfg(feature = "server")]
use axum::routing::{delete, get, post};
#[cfg(feature = "server")]
use super::ServerRuntime;
pub const ADMIN_PATH: &str = "/admin";
#[cfg(feature = "server")]
const INDEX_HTML: &str = include_str!("assets/index.html");
#[cfg(feature = "server")]
const APP_JS: &str = include_str!("assets/app.js");
#[cfg(feature = "server")]
const STYLE_CSS: &str = include_str!("assets/style.css");
#[cfg(feature = "server")]
async fn serve_index() -> impl IntoResponse {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
INDEX_HTML,
)
}
#[cfg(feature = "server")]
async fn serve_app_js() -> impl IntoResponse {
(
StatusCode::OK,
[(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)],
APP_JS,
)
}
#[cfg(feature = "server")]
async fn serve_style_css() -> impl IntoResponse {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/css; charset=utf-8")],
STYLE_CSS,
)
}
#[cfg(feature = "server")]
const FAVICON_SVG: &str = r##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#4ea1ff"/><text x="16" y="22" font-family="Segoe UI, Arial, sans-serif" font-size="16" font-weight="700" text-anchor="middle" fill="#06101e">SF</text></svg>"##;
#[cfg(feature = "server")]
async fn serve_favicon() -> impl IntoResponse {
(
StatusCode::OK,
[
(header::CONTENT_TYPE, "image/svg+xml"),
(header::CACHE_CONTROL, "public, max-age=86400"),
],
FAVICON_SVG,
)
}
#[cfg(feature = "server")]
pub fn build_admin_router(runtime: &ServerRuntime) -> Router {
Router::new()
.route(ADMIN_PATH, get(serve_index))
.route("/admin/", get(serve_index))
.route("/admin/app.js", get(serve_app_js))
.route("/admin/style.css", get(serve_style_css))
.route("/admin/favicon.svg", get(serve_favicon))
.route("/favicon.ico", get(serve_favicon))
.route("/api/v1/summary", get(api_v1::get_summary))
.route("/api/v1/surface", get(api_v1::get_surface))
.route("/api/v1/harness", get(api_v1::get_harness))
.route("/api/v1/system", get(api_v1::get_system))
.route(
"/api/v1/keys",
get(api_v1::list_keys).post(api_v1::mint_key),
)
.route("/api/v1/keys/{id}/rotate", post(api_v1::rotate_key))
.route("/api/v1/keys/{id}", delete(api_v1::revoke_key))
.with_state(runtime.clone())
}
#[cfg(all(test, feature = "server"))]
mod tests {
use super::*;
#[test]
fn embedded_assets_are_non_empty_and_reference_endpoints() {
assert!(INDEX_HTML.contains("/admin/app.js"));
assert!(INDEX_HTML.contains("/admin/style.css"));
assert!(!STYLE_CSS.is_empty());
for endpoint in ["/summary", "/surface", "/harness", "/system", "/keys"] {
assert!(
APP_JS.contains(endpoint),
"app.js must reference {endpoint}"
);
}
}
#[test]
fn favicon_asset_present_and_linked() {
assert!(FAVICON_SVG.contains("<svg"));
assert!(FAVICON_SVG.contains("</svg>"));
assert!(
INDEX_HTML.contains("/admin/favicon.svg"),
"index.html must link the favicon"
);
}
#[test]
fn mobile_overflow_guards_present_in_assets() {
assert!(
STYLE_CSS.contains(".table-scroll"),
"style.css must define the horizontal scroll container"
);
assert!(
STYLE_CSS.contains("max-width: 480px"),
"style.css must carry the <=480px mobile media query"
);
assert!(
APP_JS.contains("table-scroll"),
"app.js must wrap the harness table in a scroll container"
);
assert!(
APP_JS.contains("path-cell"),
"app.js must tag the config path cell for wrapping"
);
}
}