Skip to content

Commit

Permalink
Redirect old site URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 1, 2011
1 parent 63d8bb0 commit 4c55a40
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/PGXN/Site/Router.pm
Expand Up @@ -93,6 +93,23 @@ sub app {
resource '/error' => sub {
GET { $controller->server_error(@_) };
};

# Handle legacy URLs.
my %url_for = (
contact => '/feedback/',
contributors => '/backers/',
mirroring => '/mirroring/',
faq => '/faq/',
);

resource qr{^/(cont(?:ributors|act)|mirroring|faq)[.]html$} => sub {
GET {
my ($env, $args) = @_;
my $res = Plack::Response->new;
$res->redirect($url_for{ $args->{splat}[0] }, 301);
$res->finalize;
};
};
};

builder {
Expand Down
21 changes: 20 additions & 1 deletion t/router.t
Expand Up @@ -3,7 +3,7 @@
use 5.12.0;
use utf8;
BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Test' }
use Test::More tests => 265;
use Test::More tests => 281;
#use Test::More 'no_plan';
use Plack::Test;
use HTTP::Request::Common;
Expand Down Expand Up @@ -316,6 +316,25 @@ test_psgi $app => sub {
}
};

# Test legacy URLs.
test_psgi $app => sub {
my $cb = shift;
for my $spec (
[ contact => '/feedback/' ],
[ contributors => '/backers/' ],
[ mirroring => '/mirroring/' ],
[ faq => '/faq/' ],
) {
my $uri = "/$spec->[0].html";
ok my $res = $cb->(GET $uri), "Fetch $uri";
ok !$res->is_success, 'Should not be a success';
is $res->code, 301, 'Should get 301 response';
is $res->headers->header('location'), $spec->[1],
"Should redirect to $spec->[1]";
}
};


# Test /error.
my $err_app = sub {
my $env = shift;
Expand Down

0 comments on commit 4c55a40

Please sign in to comment.