crates/server: REST API routes; RBAC auth middleware; cookie sessions; dashboard
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5298a925bd9c11780e49d8b1c98eebd86a6a6964
This commit is contained in:
parent
44d1ee1d6b
commit
235d3d38a6
38 changed files with 6275 additions and 7 deletions
28
crates/server/src/routes/health.rs
Normal file
28
crates/server/src/routes/health.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use axum::{Json, Router, extract::State, routing::get};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct HealthResponse {
|
||||
status: &'static str,
|
||||
database: bool,
|
||||
}
|
||||
|
||||
async fn health_check(State(state): State<AppState>) -> Json<HealthResponse> {
|
||||
let db_ok = sqlx::query_scalar::<_, i32>("SELECT 1")
|
||||
.fetch_one(&state.pool)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let status = if db_ok { "ok" } else { "degraded" };
|
||||
|
||||
Json(HealthResponse {
|
||||
status,
|
||||
database: db_ok,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new().route("/health", get(health_check))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue