feat: allow customizing index header

This commit is contained in:
əlemi 2024-12-03 01:35:54 +01:00
parent db08186911
commit ec77fe6a99
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 8 additions and 6 deletions

View file

@ -75,7 +75,7 @@
</head> </head>
<body> <body>
<h1>uppe.rs</h1> <h1>uppe.rs</h1>
<p>keeping track of your infra's up status</p> <p>%%DESCRIPTION%%</p>
<hr class="color"/> <hr class="color"/>
<small style="display: block" class="rev">now --&gt;</small> <small style="display: block" class="rev">now --&gt;</small>

View file

@ -23,6 +23,9 @@ struct Config {
/// defined services, singular because makes more sense in toml /// defined services, singular because makes more sense in toml
service: std::collections::BTreeMap<String, Service>, service: std::collections::BTreeMap<String, Service>,
/// service description shown in web page
description: Option<String>,
/// how many samples of history to keep /// how many samples of history to keep
//history: usize, //history: usize,
@ -85,9 +88,12 @@ async fn entry(cli: Cli, config: Config, db: Database) -> Result<(), Box<dyn std
}); });
} }
let index = include_str!("../index.html")
.replacen("%%DESCRIPTION%%", config.description.as_deref().unwrap_or("keeping track of your infra's up status"), 1);
// build our application with a single route // build our application with a single route
let app = axum::Router::new() let app = axum::Router::new()
.route("/", axum::routing::get(root)) .route("/", axum::routing::get(|| async { Html(index) }))
.route("/api/status", axum::routing::get(api_status)) .route("/api/status", axum::routing::get(api_status))
.route("/api/status/:service", axum::routing::get(api_status_service)) .route("/api/status/:service", axum::routing::get(api_status_service))
.with_state(db); .with_state(db);
@ -134,10 +140,6 @@ impl IntoResponse for ApiError {
} }
} }
async fn root() -> Html<&'static str> {
Html(include_str!("../index.html"))
}
use axum::{extract::{Path, Query, State}, response::{Html, IntoResponse}, Json}; use axum::{extract::{Path, Query, State}, response::{Html, IntoResponse}, Json};
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]