package MyMojoliciousApp; use strict; use warnings; use base 'Mojolicious'; # This method will run for each request sub dispatch { my ($self, $c) = @_; # Try to find a static file $self->static->dispatch($c); # Use routes if we don't have a response code yet $self->routes->dispatch($c) unless $c->res->code; # Nothing found unless ($c->res->code) { $self->static->serve($c, '/404.html'); $c->res->code(404); } } # This method will run once at server start sub startup { my $self = shift; # The routes my $r = $self->routes; # Default route $r->route('/:controller/:action/:id') ->to(controller => 'example', action => 'welcome', id => 1); } 1;