Files
Krys4lide/crates/app/src/lib.rs

22 lines
673 B
Rust
Raw Normal View History

use std::path::PathBuf;
2024-08-04 18:34:42 +02:00
use axum::http::{StatusCode, Uri};
use axum_htmx::AutoVaryLayer;
use tower_http::services::ServeDir;
mod menu;
mod pages;
2024-08-04 18:34:42 +02:00
async fn fallback(uri: Uri) -> (StatusCode, String) {
(StatusCode::NOT_FOUND, format!("No route for {uri}"))
}
pub async fn get_router(assets_path: PathBuf) -> axum::Router<()> {
2024-08-04 18:34:42 +02:00
axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.merge(pages::get_routes())
2024-08-04 18:34:42 +02:00
.fallback(fallback)
// The AutoVaryLayer is used to avoid cache issues with htmx (cf: https://github.com/robertwayne/axum-htmx?tab=readme-ov-file#auto-caching-management)
.layer(AutoVaryLayer)
}