2024-09-16 22:46:53 +02:00
|
|
|
use std::path::PathBuf;
|
2024-07-23 20:08:45 +02:00
|
|
|
|
2024-08-04 18:34:42 +02:00
|
|
|
use axum::http::{StatusCode, Uri};
|
2024-08-27 10:55:17 +02:00
|
|
|
use axum_htmx::AutoVaryLayer;
|
2024-07-23 20:08:45 +02:00
|
|
|
use tower_http::services::ServeDir;
|
|
|
|
|
2024-08-23 18:45:43 +02:00
|
|
|
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}"))
|
2024-07-23 20:08:45 +02:00
|
|
|
}
|
|
|
|
|
2024-09-16 22:46:53 +02:00
|
|
|
pub async fn get_router(assets_path: PathBuf) -> axum::Router<()> {
|
2024-08-04 18:34:42 +02:00
|
|
|
axum::Router::new()
|
2024-07-23 20:08:45 +02:00
|
|
|
.nest_service("/assets", ServeDir::new(assets_path))
|
2024-08-23 18:45:43 +02:00
|
|
|
.merge(pages::get_routes())
|
2024-08-04 18:34:42 +02:00
|
|
|
.fallback(fallback)
|
2024-08-27 10:56:04 +02:00
|
|
|
// The AutoVaryLayer is used to avoid cache issues with htmx (cf: https://github.com/robertwayne/axum-htmx?tab=readme-ov-file#auto-caching-management)
|
2024-08-23 19:46:28 +02:00
|
|
|
.layer(AutoVaryLayer)
|
2024-07-23 20:08:45 +02:00
|
|
|
}
|