App aus Dateinamen entfernt
This commit is contained in:
115
xxx/app/lib/Xxx.pm
Normal file
115
xxx/app/lib/Xxx.pm
Normal file
@@ -0,0 +1,115 @@
|
||||
package Xxx;
|
||||
use Mojo::Base 'Mojolicious';
|
||||
use Time::localtime;
|
||||
|
||||
# This method will run once at server start
|
||||
sub startup {
|
||||
my $self = shift;
|
||||
|
||||
# einlesen der lokalen Config
|
||||
my $config = $self->plugin('Config');
|
||||
|
||||
$self->secrets([ $config->{secret}]);
|
||||
|
||||
$config->{version} = '__VERSION__';
|
||||
$config->{prefix} = '';
|
||||
|
||||
# Logging mit Log4perl
|
||||
$self->plugin('steffen::MojoPlug::Syslog' => $config->{logging} );
|
||||
$self->app->log->info(sprintf('%s v%s (Perl %s, Mojolicious v%s) started', 'Xxx', $config->{version}, $^V, $Mojolicious::VERSION));
|
||||
|
||||
# Authentication & Authorization
|
||||
$self->sessions->cookie_name('Xxx');
|
||||
$self->sessions->default_expiration(3600);
|
||||
$self->sessions->samesite('Strict');
|
||||
delete $self->app->static->extra->{'favicon.ico'};
|
||||
push @{$self->app->static->paths}, $config->{htlib};
|
||||
|
||||
# Kompression
|
||||
$self->app->renderer->compress(1);
|
||||
|
||||
# Authorisation
|
||||
$self->plugin('steffen::MojoPlug::Authorization' => { verbose => 1 });
|
||||
|
||||
# Menu über config
|
||||
$self->plugin('Config', file => 'navigation.conf');
|
||||
$self->plugin('steffen::MojoPlug::NavHelper' => { verbose => 1, bs => 5 });
|
||||
|
||||
# deaktivierte Plugins
|
||||
# $self->plugin('RenderFile');
|
||||
# mysql
|
||||
# $self->plugin('steffen::MojoPlug::Mysql' => { db => $config->{db} });
|
||||
# $config->{test} = $self->dbxxx->{dsn} =~ m/dbs-test/gxms;
|
||||
|
||||
# Local Helpers
|
||||
$self->plugin('Xxx::Helpers' => { verbose => 1 });
|
||||
|
||||
# https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml
|
||||
$self->plugin('OpenAPI' => {
|
||||
#route => $self->app->routes->under("/api")->to("api#auth"),
|
||||
url => $self->app->home->rel_file("openapi.json"),
|
||||
schema => 'v3',
|
||||
security => {
|
||||
BasicAuth => sub {
|
||||
my ($c, $definition, $scopes, $cb) = @_;
|
||||
my $haspriv;
|
||||
for my $sc ( @{$scopes} ) {
|
||||
$haspriv = 1 if $c->has_priv($sc);
|
||||
}
|
||||
|
||||
if ( $haspriv ) {
|
||||
return $c->$cb()
|
||||
} else {
|
||||
return $c->$cb('no permission')
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$self->plugin( 'steffen::MojoPlug::SwaggerUI' => {
|
||||
route => $self->app->routes()->any('/rfc'),
|
||||
url => "/api",
|
||||
title => "Xxx",
|
||||
favicon => "/images/favicon.png"
|
||||
}
|
||||
);
|
||||
|
||||
$self->hook(
|
||||
'before_dispatch' => sub {
|
||||
my $c = shift;
|
||||
$c->req->url->base->path('');
|
||||
$config->{prefix} = '';
|
||||
if (!!$c->req->headers->header('Mojo-RP-Location')) {
|
||||
$c->req->url->base->path( $c->req->headers->header('Mojo-RP-Location') );
|
||||
$config->{prefix} = '/'.$c->req->headers->header('Mojo-RP-Location');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# Hook für CORS
|
||||
$self->hook(
|
||||
'after_dispatch' => sub {
|
||||
my $c = shift;
|
||||
$c->res->headers->header('Access-Control-Allow-Origin' => '*');
|
||||
$c->res->headers->remove('Server');
|
||||
}
|
||||
);
|
||||
|
||||
# Router
|
||||
my $r = $self->routes;
|
||||
|
||||
# Normal route to controller
|
||||
$r->get('/') ->to('main#main', title => 'Xxx');
|
||||
$r->get('/jstreetemplate') ->to('menu#jstreetemplate', title => 'JStree Template'); # Beispiel kann gelöscht werden
|
||||
|
||||
$r->get('/xxx') ->to('main#xxx', title => 'Xxx');
|
||||
$r->get('/about') ->to('main#about', title => 'Über Xxx');
|
||||
$r->get('/login') ->to('main#loginform');
|
||||
$r->post('/login') ->to('main#login');
|
||||
$r->get('/userinfo') ->to('main#userinfo');
|
||||
$r->get('/getoff') ->to('main#getoff');
|
||||
|
||||
# API über OpenAPI Plugin
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user