fix some WebGUI::Paths stuff, multi-site plackup
This commit is contained in:
parent
8c3ecce95f
commit
cd9afc78b9
5 changed files with 60 additions and 76 deletions
79
app.psgi
79
app.psgi
|
|
@ -1,66 +1,25 @@
|
||||||
use strict;
|
use strict;
|
||||||
use Plack::Builder;
|
use Plack::Builder;
|
||||||
use lib '/data/WebGUI/lib';
|
use WebGUI::Paths -inc;
|
||||||
use WebGUI;
|
use WebGUI::Config;
|
||||||
|
use File::Spec;
|
||||||
|
|
||||||
my $root = '/data/WebGUI';
|
my $standard_psgi = File::Spec->catfile(WebGUI::Paths->var, 'site.psgi');
|
||||||
|
|
||||||
builder {
|
builder {
|
||||||
mount "http://dev.localhost.localdomain/" => builder {
|
my $first_app;
|
||||||
|
for my $config_file (WebGUI::Paths->siteConfigs) {
|
||||||
my $wg = WebGUI->new( root => $root, site => 'dev.localhost.localdomain.conf' );
|
my $config = WebGUI::Config->new($config_file);
|
||||||
my $config = $wg->config;
|
my $psgi = $config->get('psgiFile') || $standard_psgi;
|
||||||
enable 'Log4perl', category => 'mysite', conf => "$root/etc/log.conf";
|
my $app = do {
|
||||||
|
$ENV{WEBGUI_CONFIG} = $config_file;
|
||||||
# Reproduce URL handler functionality with middleware
|
Plack::Util::load_psgi($psgi);
|
||||||
enable '+WebGUI::Middleware::Snoop';
|
};
|
||||||
enable 'Static', root => $root, path => sub {s{^/\*give-credit-where-credit-is-due\*$}{docs/credits.txt}};
|
$first_app ||= $app;
|
||||||
enable 'Status', path => qr{^/uploads/dictionaries}, status => 401;
|
for my $sitename ( @{ $config->get('sitename') } ) {
|
||||||
|
mount "http://$sitename/" => $app;
|
||||||
# For PassThru, use Plack::Builder::mount
|
}
|
||||||
|
}
|
||||||
# Extras fallback (you should be using something else to serve static files in production)
|
mount '/' => $first_app;
|
||||||
my ( $extrasURL, $extrasPath ) = ( $config->get('extrasURL'), $config->get('extrasPath') );
|
|
||||||
enable 'Static', root => "$extrasPath/", path => sub {s{^$extrasURL/}{}};
|
|
||||||
|
|
||||||
# Open/close the WebGUI::Session at the outer-most onion layer
|
|
||||||
enable '+WebGUI::Middleware::Session',
|
|
||||||
config => $config,
|
|
||||||
error_docs => { 500 => "$root/www/maintenance.html" };
|
|
||||||
|
|
||||||
# This one uses the Session object, so it comes after WebGUI::Middleware::Session
|
|
||||||
enable '+WebGUI::Middleware::WGAccess', config => $config;
|
|
||||||
|
|
||||||
# Return the app
|
|
||||||
$wg->psgi_app;
|
|
||||||
};
|
|
||||||
|
|
||||||
mount "http://dev2.localhost.localdomain/" => builder {
|
|
||||||
|
|
||||||
my $wg = WebGUI->new( root => $root, site => 'dev2.localhost.localdomain.conf' );
|
|
||||||
my $config = $wg->config;
|
|
||||||
enable 'Log4perl', category => 'mysite', conf => "$root/etc/log.conf";
|
|
||||||
|
|
||||||
# Reproduce URL handler functionality with middleware
|
|
||||||
enable '+WebGUI::Middleware::Snoop';
|
|
||||||
enable 'Static', root => $root, path => sub {s{^/\*give-credit-where-credit-is-due\*$}{docs/credits.txt}};
|
|
||||||
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{^$extrasURL/}{}};
|
|
||||||
|
|
||||||
# Open/close the WebGUI::Session at the outer-most onion layer
|
|
||||||
enable '+WebGUI::Middleware::Session',
|
|
||||||
config => $config,
|
|
||||||
error_docs => { 500 => "$root/www/maintenance.html" };
|
|
||||||
|
|
||||||
# This one uses the Session object, so it comes after WebGUI::Middleware::Session
|
|
||||||
enable '+WebGUI::Middleware::WGAccess', config => $config;
|
|
||||||
|
|
||||||
# Return the app
|
|
||||||
$wg->psgi_app;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ These subroutines are available from this package:
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
has root => ( is => 'ro', isa => 'Str', default => '/data/WebGUI' );
|
|
||||||
has site => ( is => 'ro', isa => 'Str', default => 'dev.localhost.localdomain.conf' );
|
has site => ( is => 'ro', isa => 'Str', default => 'dev.localhost.localdomain.conf' );
|
||||||
has config => ( is => 'rw', isa => 'WebGUI::Config' );
|
has config => ( is => 'rw', isa => 'WebGUI::Config' );
|
||||||
|
|
||||||
|
|
@ -75,7 +74,7 @@ sub BUILD {
|
||||||
$self->config($config);
|
$self->config($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub psgi_app {
|
sub to_app {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->{psgi_app} ||= $self->compile_psgi_app;
|
return $self->{psgi_app} ||= $self->compile_psgi_app;
|
||||||
}
|
}
|
||||||
|
|
@ -83,10 +82,6 @@ sub psgi_app {
|
||||||
sub compile_psgi_app {
|
sub compile_psgi_app {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
# Preload all modules in the master (parent) thread before the Server does any
|
|
||||||
# child forking. This should save a lot of memory in copy-on-write friendly environments.
|
|
||||||
$self->preload;
|
|
||||||
|
|
||||||
# WebGUI is a PSGI app is a Perl code reference. Let's create one.
|
# WebGUI is a PSGI app is a Perl code reference. Let's create one.
|
||||||
# Each web request results in a call to this sub
|
# Each web request results in a call to this sub
|
||||||
return sub {
|
return sub {
|
||||||
|
|
@ -143,11 +138,6 @@ sub compile_psgi_app {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub preload {
|
|
||||||
WebGUI::Paths->preloadAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub handle {
|
sub handle {
|
||||||
my ( $session ) = @_;
|
my ( $session ) = @_;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ sub call {
|
||||||
|
|
||||||
my $app = $self->app;
|
my $app = $self->app;
|
||||||
weaken $self->{config};
|
weaken $self->{config};
|
||||||
|
|
||||||
my $config = $self->config or die 'Mandatory config parameter missing';
|
my $config = $self->config or die 'Mandatory config parameter missing';
|
||||||
|
|
||||||
# Logger fallback
|
# Logger fallback
|
||||||
|
|
@ -46,7 +46,7 @@ sub call {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $session = try {
|
my $session = try {
|
||||||
$env->{'webgui.session'} = WebGUI::Session->open( $config->getWebguiRoot, $config, $env );
|
$env->{'webgui.session'} = WebGUI::Session->open( $config, $env );
|
||||||
} catch {
|
} catch {
|
||||||
# We don't have a logger object, so for now just warn() the error
|
# We don't have a logger object, so for now just warn() the error
|
||||||
warn "Unable to instantiate WebGUI::Session - $_";
|
warn "Unable to instantiate WebGUI::Session - $_";
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ Returns the list of modules to exclude from preloading as an array.
|
||||||
|
|
||||||
sub preloadExclude {
|
sub preloadExclude {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my @excludes = _readTextLines($class->preloadExclude);
|
my @excludes = _readTextLines($class->preloadExclusions);
|
||||||
return @excludes;
|
return @excludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,8 +217,9 @@ sub preloadAll {
|
||||||
|
|
||||||
require WebGUI::Pluggable;
|
require WebGUI::Pluggable;
|
||||||
|
|
||||||
|
my @exclusions = $class->preloadExclude;
|
||||||
WebGUI::Pluggable::findAndLoad( 'WebGUI', {
|
WebGUI::Pluggable::findAndLoad( 'WebGUI', {
|
||||||
exclude => \( $class->preloadExclude ),
|
exclude => \@exclusions,
|
||||||
onLoadFail => sub { warn sprintf "Error loading %s: %s\n", @_ },
|
onLoadFail => sub { warn sprintf "Error loading %s: %s\n", @_ },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +227,7 @@ sub preloadAll {
|
||||||
sub _readTextLines {
|
sub _readTextLines {
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
my @lines;
|
my @lines;
|
||||||
open my $fh, '<', $file or croak "Cannot open $file: $!";
|
open my $fh, '<', $file or return;
|
||||||
while (my $line = <$fh>) {
|
while (my $line = <$fh>) {
|
||||||
$line =~ s/#.*//;
|
$line =~ s/#.*//;
|
||||||
$line =~ s/^\s+//;
|
$line =~ s/^\s+//;
|
||||||
|
|
|
||||||
34
var/site.psgi
Normal file
34
var/site.psgi
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
use strict;
|
||||||
|
use Plack::Builder;
|
||||||
|
use WebGUI;
|
||||||
|
use WebGUI::Paths;
|
||||||
|
|
||||||
|
my $config = $ENV{WEBGUI_CONFIG};
|
||||||
|
builder {
|
||||||
|
my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} );
|
||||||
|
my $config = $wg->config;
|
||||||
|
|
||||||
|
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
|
||||||
|
|
||||||
|
# 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{^$extrasURL/}{}};
|
||||||
|
|
||||||
|
# Open/close the WebGUI::Session at the outer-most onion layer
|
||||||
|
enable '+WebGUI::Middleware::Session',
|
||||||
|
config => $config,
|
||||||
|
error_docs => { 500 => $config->get('maintenancePage') };
|
||||||
|
|
||||||
|
# This one uses the Session object, so it comes after WebGUI::Middleware::Session
|
||||||
|
enable '+WebGUI::Middleware::WGAccess', config => $config;
|
||||||
|
|
||||||
|
# Return the app
|
||||||
|
$wg->to_app;
|
||||||
|
};
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue