shrl.be/lib/Shrlbe.pm

36 lines
798 B
Perl
Raw Permalink Normal View History

2023-06-18 09:57:40 +03:00
package Shrlbe;
use Mojo::Base 'Mojolicious', -signatures;
use Shrlbe::Utils;
my $SITE_NAME = 'shrl.be';
my $db_file = 'shrl.db';
# This method will run once at server start
sub startup ($self) {
# Load configuration from config file
my $config = $self->plugin('NotYAMLConfig');
# Configure the application
$self->secrets($config->{secrets});
my $utils = Shrlbe::Utils->new();
$self->helper(site_name => sub { return $SITE_NAME });
$self->helper(db_file => sub { return $db_file });
$self->helper(sh_utils => sub { return $utils });
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to('main#index');
$r->get('/s/*url')->to('main#short_api');
$r->post('/')->to('main#short');
$r->get('/:shorten_path')->to('main#get_shorten');
}
1;