feat: ✨ role routing
This commit is contained in:
parent
00d6bd5b93
commit
d0187b1b42
7 changed files with 172 additions and 6 deletions
24
src/routing.rs
Normal file
24
src/routing.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
pub mod role;
|
||||
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Router};
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
use crate::{database, AppState};
|
||||
|
||||
pub async fn route(State(app_state): State<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/", get(alive))
|
||||
.nest(
|
||||
"/role",
|
||||
role::route(axum::extract::State(app_state.clone())),
|
||||
)
|
||||
.layer(CorsLayer::permissive())
|
||||
.with_state(app_state)
|
||||
}
|
||||
|
||||
async fn alive(State(app_state): State<AppState>) -> impl IntoResponse {
|
||||
match database::is_alive(&app_state.database_connection).await {
|
||||
true => StatusCode::OK,
|
||||
false => StatusCode::SERVICE_UNAVAILABLE,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue