2022-11-09 13:31:58 +01:00
|
|
|
package BurguillosInfo;
|
2022-11-15 23:30:37 +01:00
|
|
|
|
|
|
|
use BurguillosInfo::Controller::Metrics;
|
|
|
|
|
2022-11-09 13:31:58 +01:00
|
|
|
use Mojo::Base 'Mojolicious', -signatures;
|
|
|
|
|
|
|
|
# This method will run once at server start
|
|
|
|
sub startup ($self) {
|
2022-11-15 23:57:20 +01:00
|
|
|
my $metrics = BurguillosInfo::Controller::Metrics->new;
|
|
|
|
$self->hook(
|
|
|
|
around_dispatch => sub {
|
|
|
|
my $next = shift;
|
|
|
|
my $c = shift;
|
|
|
|
$metrics->request($c);
|
|
|
|
if ( defined $next ) {
|
|
|
|
$next->();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
my $config = $self->plugin('JSONConfig');
|
|
|
|
$self->config(
|
|
|
|
hypnotoad => { proxy => 1, listen => ['http://localhost:3000'] } );
|
2023-05-02 00:45:43 +02:00
|
|
|
$self->config(css_version => int(rand(10000)));
|
2022-11-17 00:44:20 +01:00
|
|
|
$self->secrets($self->config->{secrets});
|
2022-11-15 23:57:20 +01:00
|
|
|
|
|
|
|
# Router
|
|
|
|
my $r = $self->routes;
|
|
|
|
|
|
|
|
# Normal route to controller
|
|
|
|
$r->get('/')->to('Page#index');
|
2023-05-02 03:23:18 +02:00
|
|
|
$r->get('/sitemap.xml')->to('Sitemap#sitemap');
|
2022-11-15 23:57:20 +01:00
|
|
|
|
|
|
|
# $r->get('/:post')->to('Page#post');
|
2022-11-17 00:44:20 +01:00
|
|
|
$r->get('/stats')->to('Metrics#stats');
|
2022-11-15 23:57:20 +01:00
|
|
|
$r->get('/<:category>.rss')->to('Page#category_rss');
|
|
|
|
$r->get('/:category')->to('Page#category');
|
|
|
|
$r->get('/posts/<:slug>-preview.png')->to('Page#get_post_preview');
|
|
|
|
$r->get('/posts/:slug')->to('Page#post');
|
2022-11-17 00:44:20 +01:00
|
|
|
$r->get('/stats/login')->to('Metrics#login');
|
|
|
|
$r->post('/stats/login')->to('Metrics#submit_login');
|
2022-11-09 13:31:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|