Skip to content

Commit

Permalink
Issue #138: standardize the enable and enable_if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Jul 6, 2020
1 parent 3328940 commit 618dd49
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions bin/psgi-bin/otobo.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,14 @@ my $DBViewerApp = builder {
enable $AdminOnlyMiddeware;

# rewrite PATH_INFO, not sure why, but at least it seems to work
enable 'Rewrite', request => sub {
$_ ||= '/dbviewer/';
$_ = '/dbviewer/' if $_ eq '/';
$_ = '/otobo/dbviewer' . $_;
enable 'Plack::Middleware::Rewrite',
request => sub {
$_ ||= '/dbviewer/';
$_ = '/dbviewer/' if $_ eq '/';
$_ = '/otobo/dbviewer' . $_;

1;
};
1;
};

my $server = Mojo::Server::PSGI->new;
$server->load_app("$Bin/../mojo-bin/dbviewer.pl");
Expand All @@ -454,31 +455,35 @@ my $DBViewerApp = builder {
my $StaticApp = builder {

# Cache css-cache for 30 days
enable_if { $_[0]->{PATH_INFO} =~ m{skins/.*/.*/css-cache/.*\.(?:css|CSS)$} } 'Header', set => [ 'Cache-Control' => 'max-age=2592000 must-revalidate' ];
enable_if { $_[0]->{PATH_INFO} =~ m{skins/.*/.*/css-cache/.*\.(?:css|CSS)$} } 'Plack::Middleware::Header',
set => [ 'Cache-Control' => 'max-age=2592000 must-revalidate' ];

# Cache css thirdparty for 4 hours, including icon fonts
enable_if { $_[0]->{PATH_INFO} =~ m{skins/.*/.*/css/thirdparty/.*\.(?:css|CSS|woff|svn)$} } 'Header', set => [ 'Cache-Control' => 'max-age=14400 must-revalidate' ];
enable_if { $_[0]->{PATH_INFO} =~ m{skins/.*/.*/css/thirdparty/.*\.(?:css|CSS|woff|svn)$} } 'Plack::Middleware::Header',
set => [ 'Cache-Control' => 'max-age=14400 must-revalidate' ];

# Cache js-cache for 30 days
enable_if { $_[0]->{PATH_INFO} =~ m{js/js-cache/.*\.(?:js|JS)$} } 'Header', set => [ 'Cache-Control' => 'max-age=2592000 must-revalidate' ];
enable_if { $_[0]->{PATH_INFO} =~ m{js/js-cache/.*\.(?:js|JS)$} } 'Plack::Middleware::Header',
set => [ 'Cache-Control' => 'max-age=2592000 must-revalidate' ];

# Cache js thirdparty for 4 hours
enable_if { $_[0]->{PATH_INFO} =~ m{js/thirdparty/.*\.(?:js|JS)$} } 'Header', set => [ 'Cache-Control' => 'max-age=14400 must-revalidate' ];
enable_if { $_[0]->{PATH_INFO} =~ m{js/thirdparty/.*\.(?:js|JS)$} } 'Plack::Middleware::Header',
set => [ 'Cache-Control' => 'max-age=14400 must-revalidate' ];

Plack::App::File->new(root => "$Bin/../../var/httpd/htdocs")->to_app;
};

# Port of index.pl, customer.pl, public.pl, installer.pl, migration.pl, nph-genericinterface.pl to Plack.
my $App = builder {

enable "Plack::Middleware::ErrorDocument",
enable 'Plack::Middleware::ErrorDocument',
403 => '/otobo/index.pl'; # forbidden files

# GATEWAY_INTERFACE is used for determining whether a command runs in a web context
# Per default it would enable mysql_auto_reconnect.
# But mysql_auto_reconnect is explicitly disabled in Kernel::System::DB::mysql.
# OTOBO_RUNS_UNDER_PSGI indicates that PSGI is used.
enable ForceEnv =>
enable 'Plack::Middleware::ForceEnv',
OTOBO_RUNS_UNDER_PSGI => '1',
GATEWAY_INTERFACE => 'CGI/1.1';

Expand Down Expand Up @@ -574,7 +579,7 @@ my $RPCApp = builder {

# GATEWAY_INTERFACE is used for determining whether a command runs in a web context
# OTOBO_RUNS_UNDER_PSGI is a signal that PSGI is used
enable ForceEnv =>
enable 'Plack::Middleware::ForceEnv',
OTOBO_RUNS_UNDER_PSGI => '1',
GATEWAY_INTERFACE => 'CGI/1.1';

Expand Down

0 comments on commit 618dd49

Please sign in to comment.