containered launch empty web status

This commit is contained in:
Ivan I. Ovchinnikov
2026-11-16 17:37:16 +03:00
parent 84ca3d07f8
commit 5c3a1473e3
30 changed files with 4611 additions and 55 deletions
+25 -2
View File
@@ -1,7 +1,30 @@
//! Web status UI.
//!
//! Placeholder crate. Implementation starts at the Docker/status step.
pub mod routes;
pub mod state;
pub mod templates;
use anyhow::Context;
use axum::Router;
use state::WebState;
use tokio::net::TcpListener;
pub async fn run(listen: String, state: WebState) -> anyhow::Result<()> {
let app = router(state);
let listener = TcpListener::bind(&listen)
.await
.with_context(|| format!("failed to bind web listener {}", listen))?;
tracing::info!(listen = %listen, "web status listening");
axum::serve(listener, app)
.await
.context("web status server failed")?;
Ok(())
}
pub fn router(state: WebState) -> Router {
routes::router(state)
}
+37 -1
View File
@@ -1 +1,37 @@
//! routes module placeholder.
use crate::{state::WebState, templates};
use axum::{
extract::State,
response::{Html, IntoResponse},
routing::get,
Json, Router,
};
use mm_core::BridgeStatus;
use serde_json::{json, Value};
pub fn router(state: WebState) -> Router {
Router::new()
.route("/", get(index))
.route("/health", get(health))
.route("/status", get(status))
.with_state(state)
}
async fn index(State(state): State<WebState>) -> Html<String> {
Html(templates::index_html(&state.status))
}
async fn health() -> impl IntoResponse {
Json(json!({
"ok": true,
"state": "running"
}))
}
async fn status(State(state): State<WebState>) -> Json<BridgeStatus> {
Json(state.status)
}
#[allow(dead_code)]
fn _value_type_check(value: Value) -> Value {
value
}
+12 -1
View File
@@ -1 +1,12 @@
//! state module placeholder.
use mm_core::BridgeStatus;
#[derive(Debug, Clone)]
pub struct WebState {
pub status: BridgeStatus,
}
impl WebState {
pub fn new(status: BridgeStatus) -> Self {
Self { status }
}
}
+63 -1
View File
@@ -1 +1,63 @@
//! templates module placeholder.
use mm_core::BridgeStatus;
pub fn index_html(status: &BridgeStatus) -> String {
let status_json = serde_json::to_string_pretty(status)
.unwrap_or_else(|_| "{\"error\":\"failed to encode status\"}".to_string());
let escaped_json = escape_html(&status_json);
let version = escape_html(&status.bridge.version);
let server_count = status.servers.len();
format!(
r#"<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>emacs-mattermost bridge</title>
<style>
body {{
font-family: system-ui, sans-serif;
margin: 2rem;
background: #111827;
color: #e5e7eb;
}}
a {{
color: #93c5fd;
}}
pre {{
background: #030712;
border: 1px solid #374151;
padding: 1rem;
overflow: auto;
}}
.ok {{
color: #86efac;
font-weight: bold;
}}
</style>
</head>
<body>
<h1>emacs-mattermost bridge</h1>
<p>Status: <span class="ok">running</span></p>
<p>Version: {version}</p>
<p>Configured servers: {server_count}</p>
<p>
<a href="/health">/health</a> |
<a href="/status">/status</a>
</p>
<h2>Status JSON</h2>
<pre>{escaped_json}</pre>
</body>
</html>
"#
)
}
fn escape_html(input: &str) -> String {
input
.replace('&', "&amp;")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('"', "&quot;")
.replace('\'', "&#39;")
}