diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index 8b3ea27..aa36e15 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -11,7 +11,7 @@ use crate::views::posts::PostsView; use crate::views::pro::ProTemplate; use askama::Template; use axum::extract::{Path, State}; -use axum::response::Html; +use axum::response::{Html, Redirect}; use std::sync::Arc; pub async fn about_handler(State(repo): State<Arc<impl TutorRepo>>) -> Html<String> { @@ -44,6 +44,10 @@ pub async fn post_handler( Html(view.render().unwrap()) } +pub async fn post_redirect(Path(post_id): Path<String>) -> Redirect { + Redirect::permanent(&format!("/blog/{post_id}")) +} + pub async fn k12_handler() -> Html<String> { Html(K12Template {}.render().unwrap()) } diff --git a/src/main.rs b/src/main.rs index 1a495f2..7e6a164 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use axum::extract::Path; +use axum::response::Redirect; use axum::{extract::Request, routing::get, Router, ServiceExt}; use middleware::cache_control::cache_static; use posts::fs_post_repo::FsPostRepo; @@ -41,8 +43,10 @@ async fn main() { info!("initializing router..."); let app = Router::new() .route("/", get(handlers::index_handler)) - .route("/posts", get(handlers::posts_handler)) - .route("/posts/{post_id}", get(handlers::post_handler)) + .route("/posts", get(|| async { Redirect::permanent("/blog") })) + .route("/posts/{post_id}", get(handlers::post_redirect)) + .route("/blog", get(handlers::posts_handler)) + .route("/blog/{post_id}", get(handlers::post_handler)) .with_state(posts) .route("/policies", get(handlers::policies_handler)) .route("/brochure", get(handlers::brochure_handler)) |