-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmod.rs
More file actions
33 lines (30 loc) · 1.16 KB
/
mod.rs
File metadata and controls
33 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mod authn_middleware;
pub(crate) mod authz;
pub(crate) mod authzen;
pub(crate) mod health;
mod horizon_fallback;
use crate::api::authn_middleware::authentication_middleware;
use crate::api::horizon_fallback::fallback_to_horizon;
use crate::state::AppState;
use axum::{middleware, routing::any, Router};
/// Combines all API routes into a single router
pub(super) fn router(state: &AppState) -> Router<AppState> {
Router::new()
.merge(health::router())
.merge(protected_routes(state))
}
/// Creates a router for protected routes that require API key authentication
fn protected_routes(state: &AppState) -> Router<AppState> {
// Protected routes that require API key authentication
Router::new()
.merge(authz::router())
.merge(authzen::router())
// Add fallback route to handle any unmatched requests
.fallback(any(fallback_to_horizon))
// we must use layer here and not route_layer because, route_layer only
// affects routes that are defined on the router which doesn't affect fallback
.layer(middleware::from_fn_with_state(
state.clone(),
authentication_middleware,
))
}