Files
YANPM/apps/api/src/routes/api.rs

27 lines
722 B
Rust

mod auth;
mod health;
mod helper;
mod openapi;
mod restricted;
use std::sync::Arc;
use crate::routes::AppState;
pub use self::openapi::ApiDoc;
use axum::{Router, response::IntoResponse, routing::any};
pub fn get_api_router(state: Arc<AppState>) -> Router {
Router::new()
.nest("/health", health::get_health_router(state.clone()))
.merge(auth::get_basic_auth_router(state.clone()))
.merge(restricted::get_restricted_router(state.clone()))
// explicit fallback for unmatched API routes
.route("/{*wildcard}", any(api_fallback_handler))
}
async fn api_fallback_handler() -> impl IntoResponse {
(axum::http::StatusCode::NOT_FOUND, "API route not found").into_response()
}