Krys4lide/crates/app/src/lib.rs

27 lines
701 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;
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))
// .nest("/pages", old_pages::get_routes())
// .merge(old_templates::get_routes())
2024-08-04 18:34:42 +02:00
.fallback(fallback)
}