diff --git a/etc/dev.localhost.localdomain.psgi b/etc/dev.localhost.localdomain.psgi index ae98f20df..b0f6b63b9 100644 --- a/etc/dev.localhost.localdomain.psgi +++ b/etc/dev.localhost.localdomain.psgi @@ -1,23 +1,23 @@ use Plack::Builder; use lib '/data/WebGUI/lib'; use WebGUI; +WebGUI->init( root => '/data/WebGUI', config => 'dev.localhost.localdomain.conf' ); builder { - - # Populate $env from site.conf - add 'Plack::Middleware::WebGUI', - root => '/data/WebGUI', - config => 'dev.localhost.localdomain.conf'; # Handle /extras via Plack::Middleware::Static # (or Plack::Middleware::WebGUI could do this for us by looking up extrasPath and extrasURL in site.conf) - add 'Plack::Middleware::Static', + enable 'Plack::Middleware::Static', path => qr{^/extras/}, root => '/data/WebGUI/www'; # Handle /uploads via Plack::Middleware::WGAccess (including .wgaccess) # (or Plack::Middleware::WebGUI could do this for us by looking up uploadsPath and uploadsURL in site.conf) - add 'Plack::Middleware::WGAccess', + #enable 'Plack::Middleware::WGAccess', + # path => qr{^/uploads/}, + # root => '/data/domains/dev.localhost.localdomain/public'; + + enable 'Plack::Middleware::Static', path => qr{^/uploads/}, root => '/data/domains/dev.localhost.localdomain/public'; diff --git a/lib/Plack/Middleware/WebGUI.pm b/lib/Plack/Middleware/WebGUI.pm index defa4eda5..748f531f0 100644 --- a/lib/Plack/Middleware/WebGUI.pm +++ b/lib/Plack/Middleware/WebGUI.pm @@ -13,8 +13,6 @@ Plack::Middleware::WebGUI Plack Middleware that populates $env -In the future we might want to read the site.conf here and then cache it - =cut sub call { diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index f60f377de..5ebaed2cc 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -162,15 +162,17 @@ The Apache2::RequestRec object passed in by Apache's mod_perl. sub handler { my $request = shift; # either apache request object or PSGI env hash - my $server; + my ($server, $config); if ($request->isa('WebGUI::Session::Plack')) { $server = $request->server; + $config = WebGUI->config; } else { $request = Apache2::Request->new($request); $server = Apache2::ServerUtil->server; #instantiate the server api + my $configFile = shift || $request->dir_config('WebguiConfig'); #either we got a config file, or we'll build it from the request object's settings + $config = WebGUI::Config->new($server->dir_config('WebguiRoot'), $configFile); #instantiate the config object } - my $configFile = shift || $request->dir_config('WebguiConfig'); #either we got a config file, or we'll build it from the request object's settings - my $config = WebGUI::Config->new($server->dir_config('WebguiRoot'), $configFile); #instantiate the config object + my $error = ""; my $matchUri = $request->uri; my $gateway = $config->get("gateway"); @@ -231,5 +233,19 @@ sub handle_psgi { return $plack->finalize; } +# Experimental speed boost +my ($root, $config_file, $config); +sub init { + my $class = shift; + my %opts = @_; + $root = $opts{root}; + $config_file = $opts{config}; + $config = WebGUI::Config->new($root, $config_file); + warn 'INIT'; +} +sub config { $config } +sub root { $root } +sub config_file { $config_file } + 1; diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 1cc1d497b..942f3057e 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -460,7 +460,7 @@ sub open { my $configFile = shift; my $request = shift; my $server = shift; - my $config = WebGUI::Config->new($webguiRoot,$configFile); + my $config = WebGUI->config || WebGUI::Config->new($webguiRoot,$configFile); my $self = {_config=>$config, _server=>$server}; bless $self , $class; diff --git a/lib/WebGUI/Session/Plack.pm b/lib/WebGUI/Session/Plack.pm index 3446718cf..1b552ffa1 100644 --- a/lib/WebGUI/Session/Plack.pm +++ b/lib/WebGUI/Session/Plack.pm @@ -160,8 +160,8 @@ sub dir_config { my ( $self, $c ) = @_; # Translate the legacy WebguiRoot and WebguiConfig PerlSetVar's into known values - return $self->{env}->{'wg.WEBGUI_ROOT'} if $c eq 'WebguiRoot'; - return $self->{env}->{'wg.WEBGUI_CONFIG'} if $c eq 'WebguiConfig'; + return WebGUI->root if $c eq 'WebguiRoot'; + return WebGUI->config_file if $c eq 'WebguiConfig'; # Otherwise, we might want to provide some sort of support (which Apache is still around) return $self->{env}->{"wg.DIR_CONFIG.$c"};