neptune-explorer/src/html/page/not_found.rs
danda 71cf752b41 feat: add neptune-core rpc connection watchdog
closes #1

Implements a background watchdog task that:
1. calls neptune-core /network rpc every N seconds (default: 10)
2. emits log message on any state change
3. sends detailed email alert to admin on any state change

Changes:
* AppState now has internal Arc<RwLock<AppStateInner>> to permit
  watchdog task to mutate the rpc_client field.
* adjust application to AppState changes (use locks)
* not_found functions no longer accept state arg
* move state initialization into AppState::init()
* add optional alert parameters: admin-email, smtp-*
* add neptune_rpc module with watchdog task
* add alert_email module
* simplify main()
* log warnings if alert parameters not set
* add chrono dep
* add lettre dep
2024-05-25 19:16:36 -07:00

31 lines
939 B
Rust

use crate::http_util::not_found_html_err;
use crate::http_util::not_found_html_handler;
use crate::model::app_state::AppStateInner;
use axum::http::StatusCode;
use axum::response::Html;
use axum::response::Response;
use html_escaper::Escape;
pub fn not_found_page(error_msg: Option<String>) -> Html<String> {
#[derive(boilerplate::Boilerplate)]
#[boilerplate(filename = "web/html/page/not_found.html")]
#[allow(dead_code)]
pub struct NotFoundHtmlPage {
error_msg: String,
}
let not_found_page = NotFoundHtmlPage {
error_msg: error_msg.unwrap_or_default(),
};
Html(not_found_page.to_string())
}
pub fn not_found_html_response(_state: &AppStateInner, error_msg: Option<String>) -> Response {
not_found_html_err(not_found_page(error_msg))
}
#[axum::debug_handler]
pub async fn not_found_html_fallback() -> (StatusCode, Html<String>) {
not_found_html_handler(not_found_page(None))
}