1 |
dpavlin |
267 |
package Frey::Mojo; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use base 'Mojolicious'; |
7 |
|
|
|
8 |
|
|
# This method will run for each request |
9 |
|
|
sub dispatch { |
10 |
|
|
my ($self, $c) = @_; |
11 |
|
|
|
12 |
|
|
# Try to find a static file |
13 |
|
|
$self->static->dispatch($c); |
14 |
|
|
|
15 |
|
|
# Use routes if we don't have a response code yet |
16 |
|
|
$self->routes->dispatch($c) unless $c->res->code; |
17 |
|
|
|
18 |
|
|
# Nothing found |
19 |
|
|
unless ($c->res->code) { |
20 |
|
|
$self->static->serve($c, '/404.html'); |
21 |
|
|
$c->res->code(404); |
22 |
|
|
} |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
# This method will run once at server start |
26 |
|
|
sub startup { |
27 |
|
|
my $self = shift; |
28 |
|
|
|
29 |
|
|
# The routes |
30 |
|
|
my $r = $self->routes; |
31 |
|
|
|
32 |
dpavlin |
272 |
# $r->route('/:action/:class/:controller') |
33 |
|
|
# ->to(controller => 'run', action => 'markup', class => 'Frey::ClassBrowser' ); |
34 |
|
|
|
35 |
dpavlin |
318 |
# $r->route('/') |
36 |
|
|
# ->to(controller => 'run', action => 'markup', class => 'Frey::ClassBrowser'); |
37 |
dpavlin |
272 |
|
38 |
dpavlin |
318 |
$r->route('/:class') |
39 |
|
|
->to(controller => 'run', action => 'markup', class => 'Frey::Introspect' ); |
40 |
|
|
|
41 |
dpavlin |
267 |
# Default route |
42 |
dpavlin |
272 |
$r->route('/:class/:action/:controller') |
43 |
|
|
->to(controller => 'run', action => 'markup', class => 'Frey::ClassBrowser'); |
44 |
dpavlin |
318 |
|
45 |
dpavlin |
267 |
} |
46 |
|
|
|
47 |
|
|
1; |