From decbc120e3752466dcbd09b7bd36ff413af9bf99 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Wed, 14 Aug 2024 16:30:55 -0400 Subject: [PATCH] Redirect for old `/thread/post` path --- README.md | 1 - lib/PostText.pm | 5 +++++ t/redirect_old_path.t | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 t/redirect_old_path.t diff --git a/README.md b/README.md index dd1f798..a47fe7d 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ tests locally: ## TODOs -- Redirect for `/thread/post` - Implement [CSRF](https://docs.mojolicious.org/Mojolicious/Guides/Rendering#Cross-site-request-forgery) - Tripcodes/PGP signing somehow perhaps... diff --git a/lib/PostText.pm b/lib/PostText.pm index c117e82..1f68e6a 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -182,6 +182,11 @@ sub startup($self) { ->to('thread#flag') ->name('flag_thread'); + # Redirect for this old path to the new one + $thread->any([qw{GET POST}], '/post', sub ($c) { + $c->redirect_to('post_thread') + }); + $human_thread->any([qw{GET POST}], '/post') ->to('thread#create') ->name('post_thread'); diff --git a/t/redirect_old_path.t b/t/redirect_old_path.t new file mode 100644 index 0000000..b9b2c5a --- /dev/null +++ b/t/redirect_old_path.t @@ -0,0 +1,10 @@ +use Mojo::Base -strict; +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('PostText'); + +$t->get_ok('/thread/post')->status_is(302) + ->header_like(Location => qr{human/thread/post}); + +done_testing;