From d15fbc85772bde4800936bf1e11215a83449dd94 Mon Sep 17 00:00:00 2001 From: BBaoVanC Date: Sun, 10 Nov 2024 14:48:22 -0600 Subject: [PATCH] Redirect /upload and /paste without trailing slash to correct page --- bobashare-web/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bobashare-web/src/main.rs b/bobashare-web/src/main.rs index 81b672d0..396a16c6 100644 --- a/bobashare-web/src/main.rs +++ b/bobashare-web/src/main.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::Context; -use axum::{self, routing::get, Router}; +use axum::{self, response::Redirect, routing::get, Router}; use bobashare::storage::file::FileBackend; use bobashare_web::{ api, render_markdown_with_syntax_set, static_routes, str_to_duration, @@ -196,6 +196,17 @@ async fn main() -> anyhow::Result<()> { let app = Router::new() .nest("/api", api::router()) .merge(views::router()) + .route( + "/upload", + get(|| async { Redirect::permanent(state.base_url.as_str()) }), + ) + .route( + "/paste", + get({ + let paste_url = Box::leak(Box::new(state.base_url.join("paste/").unwrap())); + || async { Redirect::permanent(paste_url.as_str()) } + }), + ) .nest_service("/static", get(static_routes::handler)) .fallback(|| async { ErrorResponse::from(ErrorTemplate {