Created
January 30, 2011 09:43
-
-
Save ranguard/802724 to your computer and use it in GitHub Desktop.
Error Document not working....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use lib qw(lib); | |
use Plack::App::Cascade; | |
use Plack::Builder; | |
use Plack::Middleware::Static; | |
use Plack::Middleware::ErrorDocument; | |
use Plack::App::TemplateToolkit; | |
my $root = '/Users/leo/svn/london-pm/LPM/root'; | |
# Just to show you can build up layers, | |
my $another_app = sub { | |
return [ 200, [ 'Content-Type' => 'text/plain' ], ["You should not be here"] ]; | |
}; | |
my $tt_app = Plack::App::TemplateToolkit->new( | |
root => $root, | |
extension => '.html' | |
)->to_app; | |
my $cascade = Plack::App::Cascade->new; | |
$cascade->add($tt_app); | |
# $cascade->add($another_app); | |
my $app = builder { | |
mount '/' => $cascade; | |
}; | |
# The TT app is returning a 404 and if I do not | |
# use a subrequest then ErrorDocument also works | |
# ERROR: | |
# Not an ARRAY reference at /Users/leo/perl5/lib/perl5/Plack/Middleware/ErrorDocument.pm line 39. | |
# Dumping it out I have: | |
# It's actually getting a code ref back ($VAR1 = sub { "DUMMY" };) | |
$app = Plack::Middleware::ErrorDocument->wrap( | |
$app, | |
# Does not work???? | |
404 => "/page_not_found.html", | |
subrequest => 1 | |
); | |
$app = Plack::Middleware::Static->wrap( | |
$app, | |
path => qr{[jpg|gif|jpeg|css|js|ico]$}, | |
root => $root | |
); | |
builder { | |
$app; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment