Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide a redirect when requesting / rather than erroring
  • Loading branch information
jberger committed Nov 18, 2016
1 parent 9339e16 commit 5001fb4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/MetaCPAN/Server/Controller/Root.pm
Expand Up @@ -15,6 +15,15 @@ sub default : Path {
$c->forward( '/not_found', [] );
}

# handle /
sub all : Path('') : Args(0) {
my ( $self, $c ) = @_;
$c->res->redirect(
'https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md',
302
);
}

# The parent class has a sub with this signature but expects a namespace
# and an es type... since this controller doesn't have those, just overwrite.
sub get : Path('') : Args(1) {
Expand Down
19 changes: 19 additions & 0 deletions t/server/controller/root.t
@@ -0,0 +1,19 @@
use strict;
use warnings;

use MetaCPAN::Server::Test;
use MetaCPAN::TestHelpers;
use Test::More;

test_psgi app, sub {
my $cb = shift;
ok( my $res = $cb->( GET '/' ), "GET /" );
is( $res->code, 302, 'got redirect' );
is(
$res->header('Location'),
'https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md',
'correct redirect target'
);
};

done_testing;

0 comments on commit 5001fb4

Please sign in to comment.