- Change all instances of AppState to reference the new state module across multiple files for consistency. - Clean up imports in auth, books, index_jobs, libraries, pages, search, settings, thumbnails, and tokens modules. - Simplify main.rs by removing unused code and organizing middleware and route handlers under the new handlers module.
27 lines
846 B
Rust
27 lines
846 B
Rust
use axum::{extract::State, Json};
|
|
use std::sync::atomic::Ordering;
|
|
|
|
use crate::{error::ApiError, state::AppState};
|
|
|
|
pub async fn health() -> &'static str {
|
|
"ok"
|
|
}
|
|
|
|
pub async fn docs_redirect() -> impl axum::response::IntoResponse {
|
|
axum::response::Redirect::to("/swagger-ui/")
|
|
}
|
|
|
|
pub async fn ready(State(state): State<AppState>) -> Result<Json<serde_json::Value>, ApiError> {
|
|
sqlx::query("SELECT 1").execute(&state.pool).await?;
|
|
Ok(Json(serde_json::json!({"status": "ready"})))
|
|
}
|
|
|
|
pub async fn metrics(State(state): State<AppState>) -> String {
|
|
format!(
|
|
"requests_total {}\npage_cache_hits {}\npage_cache_misses {}\n",
|
|
state.metrics.requests_total.load(Ordering::Relaxed),
|
|
state.metrics.page_cache_hits.load(Ordering::Relaxed),
|
|
state.metrics.page_cache_misses.load(Ordering::Relaxed),
|
|
)
|
|
}
|