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;