1
0
mirror of https://gitlab.com/depesz/explain.depesz.com.git synced 2025-07-01 00:55:01 +02:00
Files
explain.depesz.com/lib/Explain.pm

109 lines
3.4 KiB
Perl
Raw Normal View History

package Explain;
use Mojo::Base 'Mojolicious';
use MojoX::Log::Rotate;
sub startup {
my $self = shift;
my $log = MojoX::Log::Rotate->new(
'path' => $self->home->child( 'log', $self->mode . '.log' ),
'frequency' => 86400
);
$self->log( $log );
2013-10-30 12:47:28 +01:00
$self->sessions->cookie_name( 'explain' );
$self->sessions->default_expiration( 60 * 60 * 24 * 365 );
# Add path to pgFormatter library, from git submodule
push @INC, $self->home->rel_file( 'ext/pgFormatter/lib' )->to_string();
# register Explain plugins namespace
$self->plugins->namespaces( [ "Explain::Plugin", @{ $self->plugins->namespaces } ] );
# load configuration
2012-01-26 11:28:02 +01:00
my $config = $self->plugin( 'JSONConfig' );
2014-10-31 06:04:52 -07:00
# setup secret passphrase - later versions of
# mojolicious require secrets to be multiple in an
# array format
my $use_secret = $config->{ secret } || 'Xwyfe-_d:yGDr+p][Vs7Kk+e3mmP=c_|s7hvExF=b|4r4^gO|';
if ( $self->can( 'secrets' ) ) {
2019-05-14 13:05:34 +02:00
# We're on Mojolicious 4.63 or newer
$self->secrets( [ $use_secret ] );
2019-05-14 13:05:34 +02:00
}
else {
# We're on old Mojolicious
$self->secret( $use_secret );
}
# startup database connection
$self->plugin( 'database', $config->{ database } || {} );
# startup mail sender
$self->plugin( 'mail_sender', $config->{ mail_sender } || {} );
# load number_format plugin
$self->plugin( 'number_format' );
2022-02-16 12:23:51 +01:00
# Plugin to to smart quoting of DB identifiers
$self->plugin( 'DBIdentQuote' );
# Plugin to check if static file exists
$self->plugin( 'Explain::Plugin::StaticExists' );
# routes
my $routes = $self->routes;
# route: 'index'
2021-03-05 14:03:24 +01:00
$routes->any( '/' )->to( 'controller#index' )->name( 'new-explain' );
# route: 'status'
2021-03-05 14:03:24 +01:00
$routes->any( '/status' )->to( 'controller#status' )->name( 'status' );
2017-05-19 18:45:41 +02:00
# route: 'new-optimization'
2021-03-05 14:03:24 +01:00
$routes->any( '/new_optimization' )->to( 'controller#new_optimization' )->name( 'new-optimization' );
2017-05-19 18:45:41 +02:00
# route: 'user-history'
2021-03-05 14:03:24 +01:00
$routes->any( '/user-history/:direction/:key' )->to( 'controller#user_history', direction => undef, key => undef )->name( 'user-history' );
# route: 'plan-change'
2021-03-05 14:03:24 +01:00
$routes->any( '/plan-change/:id' )->to( 'controller#plan_change' )->name( 'plan-change' );
# route: 'login'
2021-03-05 14:03:24 +01:00
$routes->any( '/login' )->to( 'controller#login' )->name( 'login' );
# route: 'logout'
2021-03-05 14:03:24 +01:00
$routes->any( '/logout' )->to( 'controller#logout' )->name( 'logout' );
# route: 'user'
2021-03-05 14:03:24 +01:00
$routes->any( '/user' )->to( 'controller#user' )->name( 'user' );
# route: 'show'
2021-03-05 14:03:24 +01:00
$routes->any( '/s/:id' )->to( 'controller#show', id => '' )->name( 'show' );
# route: 'iframe'
2021-03-05 14:03:24 +01:00
$routes->any( '/i/:id' )->to( 'controller#show', id => '' )->name( 'iframe' );
# route: 'delete'
2021-03-05 14:03:24 +01:00
$routes->any( '/d/:id/:key' )->to( 'controller#delete', id => '', key => '' )->name( 'delete' );
# route: 'history'
2021-03-05 14:03:24 +01:00
$routes->any( '/history/:date' )->to( 'controller#history', date => '' )->name( 'history' );
# route: 'contact'
$routes->get( '/contact' )->to( 'controller#contact' )->name( 'contact' );
$routes->post( '/contact' )->to( 'controller#contact_post' )->name( 'contact_post' );
# route: 'help'
2021-03-05 14:03:24 +01:00
$routes->any( '/help' )->to( 'controller#help' )->name( 'help' );
# route: 'info'
2021-03-05 14:03:24 +01:00
$routes->any( '/info' )->to( 'controller#info' )->name( 'info' );
return;
}
1;