Krys4lide/crates/app/src/lib.rs

29 lines
701 B
Rust

mod templates;
use std::path::Path;
use askama::Template;
use askama_axum::IntoResponse;
use axum::http::{StatusCode, Uri};
use tower_http::services::ServeDir;
async fn fallback(uri: Uri) -> (StatusCode, String) {
(StatusCode::NOT_FOUND, format!("No route for {uri}"))
}
#[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 {
axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.merge(templates::get_routes())
.fallback(fallback)
}