This is minimal in implementation right now in that there's no support for passing args, which would generally be objects mixed with strings, to the middlewares being added, as would be necessary if the .psgi files were to be largely migrated to the config files. I agree that it's important that upgrade scripts be able to add middleware (probably custom ones that know how to get the session from %$env) but I'm not convinced of the utility of moving much logic out of share/site.psgi.
68 lines
2.3 KiB
Perl
68 lines
2.3 KiB
Perl
use strict;
|
|
use Plack::Builder;
|
|
use Plack::App::File;
|
|
use WebGUI;
|
|
|
|
builder {
|
|
my $wg = WebGUI->new( config => $ENV{WEBGUI_CONFIG} );
|
|
my $config = $wg->config;
|
|
|
|
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
|
|
enable 'SimpleContentFilter', filter => sub {
|
|
if ( utf8::is_utf8($_) ) {
|
|
utf8::encode($_);
|
|
}
|
|
};
|
|
|
|
# Reproduce URL handler functionality with middleware
|
|
enable '+WebGUI::Middleware::Snoop';
|
|
enable 'Status', path => qr{^/uploads/dictionaries}, status => 401;
|
|
|
|
# For PassThru, use Plack::Builder::mount
|
|
|
|
# Extras fallback (you should be using something else to serve static files in production)
|
|
my ( $extrasURL, $extrasPath ) = ( $config->get('extrasURL'), $config->get('extrasPath') );
|
|
enable 'Static', root => "$extrasPath/", path => sub {s{^\Q$extrasURL/}{}};
|
|
|
|
# Open/close the WebGUI::Session at the outer-most onion layer
|
|
enable '+WebGUI::Middleware::Session', config => $config;
|
|
|
|
enable '+WebGUI::Middleware::HTTPExceptions';
|
|
|
|
enable 'ErrorDocument', 503 => $config->get('maintenancePage');
|
|
enable_if { ! $_[0]->{'webgui.debug'} } 'ErrorDocument', 500 => $config->get('maintenancePage');
|
|
|
|
enable '+WebGUI::Middleware::Maintenance';
|
|
|
|
# enable_if { $_[0]->{'webgui.debug'} } 'StackTrace';
|
|
enable_if { $_[0]->{'webgui.debug'} } '+WebGUI::Middleware::StackTrace';
|
|
|
|
enable_if { $_[0]->{'webgui.debug'} } 'Debug', panels => [
|
|
'Timer',
|
|
'Memory',
|
|
'Session',
|
|
'Parameters',
|
|
'PerlConfig',
|
|
[ 'MySQLTrace', skip_packages => qr/\AWebGUI::SQL(?:\z|::)/ ],
|
|
'Response',
|
|
'Logger',
|
|
];
|
|
enable_if { $_[0]->{'webgui.debug'} } '+WebGUI::Middleware::Debug::Environment';
|
|
enable_if { $_[0]->{'webgui.debug'} } '+WebGUI::Middleware::Debug::Performance';
|
|
|
|
# This one uses the Session object, so it comes after WebGUI::Middleware::Session
|
|
mount $config->get('uploadsURL') => builder {
|
|
enable '+WebGUI::Middleware::WGAccess';
|
|
Plack::App::File->new(root => $config->get('uploadsPath'));
|
|
};
|
|
|
|
# enable config defined Middleware
|
|
|
|
for my $mw ( @{ $config->get('plackMiddleware') || [] } ) {
|
|
enable $mw;
|
|
}
|
|
|
|
# Return the app
|
|
mount '/' => $wg->to_app;
|
|
};
|
|
|