2011-03-10 15:19:34 +00:00
|
|
|
package Explain;
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious';
|
2023-12-27 13:46:17 +01:00
|
|
|
use MojoX::Log::Rotate;
|
2011-03-10 15:19:34 +00:00
|
|
|
|
|
|
|
sub startup {
|
|
|
|
my $self = shift;
|
|
|
|
|
2023-12-27 13:46:17 +01:00
|
|
|
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' );
|
2013-10-28 14:58:17 +01:00
|
|
|
$self->sessions->default_expiration( 60 * 60 * 24 * 365 );
|
|
|
|
|
2020-11-05 15:38:16 +01:00
|
|
|
# Add path to pgFormatter library, from git submodule
|
|
|
|
push @INC, $self->home->rel_file( 'ext/pgFormatter/lib' )->to_string();
|
|
|
|
|
2011-03-10 15:19:34 +00:00
|
|
|
# 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' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
2014-10-31 06:04:52 -07:00
|
|
|
# setup secret passphrase - later versions of
|
|
|
|
# mojolicious require secrets to be multiple in an
|
|
|
|
# array format
|
2014-10-31 15:55:59 +01:00
|
|
|
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
|
|
|
|
2014-10-31 15:55:59 +01:00
|
|
|
# We're on Mojolicious 4.63 or newer
|
|
|
|
$self->secrets( [ $use_secret ] );
|
2019-05-14 13:05:34 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-10-31 15:55:59 +01:00
|
|
|
# We're on old Mojolicious
|
|
|
|
$self->secret( $use_secret );
|
|
|
|
}
|
2011-03-10 15:19:34 +00:00
|
|
|
|
|
|
|
# startup database connection
|
|
|
|
$self->plugin( 'database', $config->{ database } || {} );
|
|
|
|
|
|
|
|
# startup mail sender
|
|
|
|
$self->plugin( 'mail_sender', $config->{ mail_sender } || {} );
|
|
|
|
|
2014-11-05 16:30:32 +01:00
|
|
|
# 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' );
|
|
|
|
|
2019-05-21 09:29:21 +02:00
|
|
|
# Plugin to check if static file exists
|
|
|
|
$self->plugin( 'Explain::Plugin::StaticExists' );
|
|
|
|
|
2011-03-10 15:19:34 +00:00
|
|
|
# routes
|
|
|
|
my $routes = $self->routes;
|
|
|
|
|
|
|
|
# route: 'index'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/' )->to( 'controller#index' )->name( 'new-explain' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
2018-06-11 20:56:49 +02:00
|
|
|
# route: 'status'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/status' )->to( 'controller#status' )->name( 'status' );
|
2018-06-11 20:56:49 +02:00
|
|
|
|
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
|
|
|
|
2013-10-29 14:35:04 +01: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' );
|
2013-10-29 14:35:04 +01:00
|
|
|
|
|
|
|
# route: 'plan-change'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/plan-change/:id' )->to( 'controller#plan_change' )->name( 'plan-change' );
|
2013-10-29 14:35:04 +01:00
|
|
|
|
2013-10-28 14:58:17 +01:00
|
|
|
# route: 'login'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/login' )->to( 'controller#login' )->name( 'login' );
|
2013-10-28 14:58:17 +01:00
|
|
|
|
|
|
|
# route: 'logout'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/logout' )->to( 'controller#logout' )->name( 'logout' );
|
2013-10-28 14:58:17 +01:00
|
|
|
|
|
|
|
# route: 'user'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/user' )->to( 'controller#user' )->name( 'user' );
|
2013-10-28 14:58:17 +01:00
|
|
|
|
2011-03-10 15:19:34 +00:00
|
|
|
# route: 'show'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/s/:id' )->to( 'controller#show', id => '' )->name( 'show' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
2019-12-03 18:55:41 +01:00
|
|
|
# route: 'iframe'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/i/:id' )->to( 'controller#show', id => '' )->name( 'iframe' );
|
2019-12-03 18:55:41 +01:00
|
|
|
|
2013-03-30 20:18:27 +01:00
|
|
|
# route: 'delete'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/d/:id/:key' )->to( 'controller#delete', id => '', key => '' )->name( 'delete' );
|
2013-03-30 20:18:27 +01:00
|
|
|
|
2011-03-10 15:19:34 +00:00
|
|
|
# route: 'history'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/history/:date' )->to( 'controller#history', date => '' )->name( 'history' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
|
|
|
# route: 'contact'
|
2019-05-21 09:29:21 +02:00
|
|
|
$routes->get( '/contact' )->to( 'controller#contact' )->name( 'contact' );
|
|
|
|
$routes->post( '/contact' )->to( 'controller#contact_post' )->name( 'contact_post' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
|
|
|
# route: 'help'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/help' )->to( 'controller#help' )->name( 'help' );
|
2011-03-10 15:19:34 +00:00
|
|
|
|
2014-10-31 22:03:11 +01:00
|
|
|
# route: 'info'
|
2021-03-05 14:03:24 +01:00
|
|
|
$routes->any( '/info' )->to( 'controller#info' )->name( 'info' );
|
2014-10-31 22:03:11 +01:00
|
|
|
|
2011-03-10 15:19:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|