use axum::{
http::{header, StatusCode},
response::{IntoResponse, Response},
routing::get,
Router,
};
pub const CHAT_UI_HTML: &str = include_str!("../assets/chat.html");
async fn serve_chat_ui() -> Response {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/html; charset=utf-8")],
CHAT_UI_HTML,
)
.into_response()
}
async fn ui_health() -> Response {
(
StatusCode::OK,
[(header::CONTENT_TYPE, "application/json")],
r#"{"status":"ok"}"#,
)
.into_response()
}
pub fn create_ui_router() -> Router {
Router::new()
.route("/ui", get(serve_chat_ui))
.route("/ui/health", get(ui_health))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn chat_ui_html_is_nonempty() {
assert!(!CHAT_UI_HTML.is_empty(), "CHAT_UI_HTML must not be empty");
}
#[test]
fn chat_ui_html_contains_doctype() {
assert!(
CHAT_UI_HTML.contains("<!DOCTYPE html>"),
"HTML should start with DOCTYPE"
);
}
#[test]
fn chat_ui_html_contains_fetch() {
assert!(
CHAT_UI_HTML.contains("fetch"),
"HTML should use fetch() for API calls"
);
}
#[test]
fn create_ui_router_does_not_panic() {
let _router = create_ui_router();
}
}