Krys4lide/crates/app/src/lib.rs

31 lines
757 B
Rust
Raw Normal View History

mod pages;
mod templates;
use std::path::Path;
2024-08-04 18:34:42 +02:00
use askama::Template;
use askama_axum::IntoResponse;
2024-08-04 18:34:42 +02:00
use axum::http::{StatusCode, Uri};
use tower_http::services::ServeDir;
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 GetIndexResponse;
async fn root() -> impl IntoResponse {
GetIndexResponse {}.into_response()
}
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))
.nest("/pages", pages::get_routes())
2024-08-04 18:34:42 +02:00
.merge(templates::get_routes())
.fallback(fallback)
}