#!/usr/bin/env perl
use Mojo::Base -strict, -signatures;
use Mojo::Util qw(sha1_sum encode);
my $home = $app->home;
my $mode = $app->mode;
my $moniker = $app->moniker;
my $rsc = $app->resources;
my $mode_routes_file = $rsc->child("etc/routes.$mode.conf");
my $routes_file
= (-e $mode_routes_file ? $mode_routes_file : $rsc->child("etc/routes.conf"));
# $app->defaults(layout => 'default',);
$app->load_class('Slovo::Controller::Auth');
{
# Some classes which plugins or the application expect to be loaded to enable
# some functionality or to refer to its functions.
load_classes => [qw()],
# Plugins can be Mojolicious and Slovo plugins.
# Every Slovo::Plugin:: ISA Mojolicious::Plugin
# Plugin order is important. Any plugin depending on another
# must come after the plugin it depends on.
# A plugin may be loaded twice if it will do different
# things depending on configuration variables.
plugins => [
'TagHelpers',
'PODRenderer',
{
MojoDBx => {
adaptor => 'SQLite',
new => $rsc->child("data/$moniker.$mode.sqlite")->to_string,
sql_debug => 0, #4,
on_connection => [
'PRAGMA synchronous = OFF', 'PRAGMA foreign_keys = ON',
'PRAGMA cache_size = 80000', #80M cache size
sub($dbh) {
$app->log->debug('SQLite version: '
. $dbh->selectrow_arrayref('select sqlite_version()')->[0]);
}
],
max_connections => 3,
auto_migrate => 1,
migration_file => $rsc->child("data/migrations.sql")->to_string,
tables => ['users', 'groups', 'domove', 'stranici', 'celini'],
}
},
{
Authentication => {
autoload_user => 1,
session_key => 'u',
current_user_fn => Slovo::Controller::Auth::current_user_fn(),
load_user => \&Slovo::Controller::Auth::load_user,
validate_user => \&Slovo::Controller::Auth::validate_user,
}
},
{RoutesConfig => {file => $routes_file}},
{OpenAPI => {url => $app->resources->child("api-v1.0.json")->to_string}}
],
secrets => [sha1_sum(encode('utf8', $home . 'тайна')),],
# See also /perldoc/Mojolicious/Sessions
sessions => [
#attribute => value
{default_expiration => 3600 * 24 * 5}, #five days
{cookie_name => 'slovo'}
],
default_language => 'bg-bg',
}