Krys4lide/crates/app/src/lib.rs

29 lines
660 B
Rust
Raw Normal View History

use std::path::Path;
use askama_axum::Template;
2024-08-04 18:34:42 +02:00
use axum::http::{StatusCode, Uri};
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}"))
}
2024-08-04 18:34:42 +02:00
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexTemplate;
2024-08-04 18:34:42 +02:00
async fn root() -> GetIndexTemplate {
GetIndexTemplate {}
}
pub fn get_router(assets_path: &Path) -> axum::Router {
2024-08-04 18:34:42 +02:00
axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.merge(pages::get_routes())
2024-08-04 18:34:42 +02:00
.fallback(fallback)
}