2024-08-06 00:18:09 +02:00
|
|
|
mod pages;
|
2024-07-23 20:08:45 +02:00
|
|
|
mod templates;
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
2024-08-04 18:34:42 +02:00
|
|
|
use askama::Template;
|
2024-07-23 20:08:45 +02:00
|
|
|
use askama_axum::IntoResponse;
|
2024-08-04 18:34:42 +02:00
|
|
|
use axum::http::{StatusCode, Uri};
|
2024-07-23 20:08:45 +02:00
|
|
|
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-07-23 20:08:45 +02:00
|
|
|
}
|
|
|
|
|
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()
|
2024-07-23 20:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_router(assets_path: &Path) -> 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))
|
|
|
|
.route("/", axum::routing::get(root))
|
2024-08-06 00:18:09 +02:00
|
|
|
.nest("/pages", pages::get_routes())
|
2024-08-04 18:34:42 +02:00
|
|
|
.merge(templates::get_routes())
|
|
|
|
.fallback(fallback)
|
2024-07-23 20:08:45 +02:00
|
|
|
}
|