vault-link/backend/sync_server/src/server/ping.rs
2024-12-20 11:08:14 +00:00

22 lines
680 B
Rust

use axum::{extract::State, Json};
use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use super::{auth::auth, responses::PingResponse};
use crate::{app_state::AppState, errors::SyncServerError};
#[axum::debug_handler]
pub async fn ping(
maybe_auth_header: Option<TypedHeader<Authorization<Bearer>>>,
State(state): State<AppState>,
) -> Result<Json<PingResponse>, SyncServerError> {
let is_authenticated =
maybe_auth_header.is_some_and(|auth_header| auth(&state, auth_header.token()).is_ok());
Ok(Json(PingResponse {
server_version: env!("CARGO_PKG_VERSION").to_owned(),
is_authenticated,
}))
}