Skip to content

Commit

Permalink
Redirect /upload and /paste without trailing slash to correct page
Browse files Browse the repository at this point in the history
  • Loading branch information
BBaoVanC committed Nov 10, 2024
1 parent e5361ff commit d15fbc8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bobashare-web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d15fbc8

Please sign in to comment.