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->();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2023-07-30 15:39:36 +02:00
|
|
|
$self->hook(
|
|
|
|
before_render => sub($c, $args) {
|
2023-09-01 16:44:07 +02:00
|
|
|
my $current_route = $c->url_for;
|
|
|
|
$c->stash(current_route => $current_route);
|
2023-07-30 15:39:36 +02:00
|
|
|
my $onion_base_url = $self->config->{onion_base_url};
|
|
|
|
my $base_url = $self->config->{base_url};
|
|
|
|
if (!defined $onion_base_url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$current_route =~ s/^$base_url//;
|
|
|
|
$c->res->headers->header('Onion-Location' => $onion_base_url.$current_route);
|
|
|
|
}
|
|
|
|
);
|
2022-11-15 23:57:20 +01:00
|
|
|
my $config = $self->plugin('JSONConfig');
|
|
|
|
$self->config(
|
2023-05-03 06:19:20 +02:00
|
|
|
hypnotoad => { proxy => 1, listen => [$self->config('listen') // 'http://localhost:3000'] } );
|
2023-05-03 05:30:29 +02:00
|
|
|
$self->config( css_version => int( rand(10000) ) );
|
|
|
|
$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-09-01 01:37:27 +02:00
|
|
|
$r->get('/privacy.txt')->to('Privacy#index');
|
2023-05-02 03:23:18 +02:00
|
|
|
$r->get('/sitemap.xml')->to('Sitemap#sitemap');
|
2023-05-03 01:02:51 +02:00
|
|
|
$r->get('/robots.txt')->to('Robots#robots');
|
2023-05-12 18:32:19 +02:00
|
|
|
$r->get('/aprende-a-dibujar-con-krita')->to('Page#rickroll');
|
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');
|
2023-05-08 01:14:36 +02:00
|
|
|
$r->get('/:category_slug/atributo/<:attribute_slug>-preview.png')->to('Attribute#get_attribute_preview');
|
2023-05-03 05:30:29 +02:00
|
|
|
$r->get('/:category_slug/atributo/:attribute_slug')->to('Attribute#get');
|
2023-05-08 01:14:36 +02:00
|
|
|
$r->get('/<:category>-preview.png')->to('Page#get_category_preview');
|
2022-11-15 23:57:20 +01:00
|
|
|
$r->get('/:category')->to('Page#category');
|
2023-05-04 00:13:49 +02:00
|
|
|
$r->get('/posts/<:slug>-preview.png')->to('Page#get_post_preview');
|
2022-11-15 23:57:20 +01:00
|
|
|
$r->get('/posts/:slug')->to('Page#post');
|
2023-08-21 00:58:11 +02:00
|
|
|
$r->get('/next-ad.json')->to('Ads#next_ad');
|
2023-05-03 05:30:29 +02:00
|
|
|
$r->get('/filtros')->to('Filter#list');
|
|
|
|
$r->get('/filtros/:slug')->to('Filter#get');
|
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;
|