Skip to main content

tuff_console/
ui.rs

1//! The console's web UI: three static files compiled into the binary. They
2//! call the JSON API under `/api/v1` and load nothing from elsewhere.
3
4use axum::http::{HeaderValue, header};
5use axum::response::{IntoResponse, Response};
6
7const INDEX: &str = include_str!("../ui/index.html");
8const STYLESHEET: &str = include_str!("../ui/app.css");
9const SCRIPT: &str = include_str!("../ui/app.js");
10
11fn file(content_type: &'static str, body: &'static str) -> Response {
12    let mut response = body.into_response();
13    let headers = response.headers_mut();
14    headers.insert(header::CONTENT_TYPE, HeaderValue::from_static(content_type));
15    // The files change with the binary, so a browser checks them each time.
16    headers.insert(header::CACHE_CONTROL, HeaderValue::from_static("no-cache"));
17    response
18}
19
20pub async fn index() -> Response {
21    file("text/html; charset=utf-8", INDEX)
22}
23
24pub async fn stylesheet() -> Response {
25    file("text/css; charset=utf-8", STYLESHEET)
26}
27
28pub async fn script() -> Response {
29    file("text/javascript; charset=utf-8", SCRIPT)
30}