perl - Custom 404 route not matching website root -
i have few routes defined mojolicious app , catch-all 404 route:
$r->any('*')->to(cb => sub { $self = shift; $self->render(text => '404 not found'); $self->rendered(404); });
the 404 route works fine:
$ ./bin/myapp.pl -m production /no_such_url 404 not found
but want 404 route match website root, , default mojolicious 404 instead, in production mode:
$ ./bin/myapp.pl -m production / <!doctype html> <html> <head><title>page not found</title></head> …
what need serve plain 404 callback on /
?
you correct any '*'
not catch main index /
. appears 1 exception. there 2 easy solutions:
you can create alias route. note how set rendered code before set rendered text:
use mojolicious::lite; sub my404 { $self = shift; $self->rendered(404); $self->render(text => '404 *'); } '*' => \&my404; '/' => \&my404; app->start;
you can override default 404 not found template documented in rendering exception , not found pages
:
use mojolicious::lite; app->start; __data__ @@ not_found.development.html.ep 404 default template
Comments
Post a Comment