diff --git a/apache.conf b/apache.conf index 7be1edbfe..71ea48165 100644 --- a/apache.conf +++ b/apache.conf @@ -18,4 +18,10 @@ FastCgiServer /data/WebGUI/etc/dev.localhost.localdomain.fcgi ScriptAlias / /data/WebGUI/etc/dev.localhost.localdomain.fcgi/ + # mod_psgi + # + # SetHandler psgi + # PSGIApp /data/WebGUI/etc/dev.localhost.localdomain.psgi + # + diff --git a/etc/dev.localhost.localdomain.perlbal b/etc/dev.localhost.localdomain.perlbal new file mode 100644 index 000000000..98b85382e --- /dev/null +++ b/etc/dev.localhost.localdomain.perlbal @@ -0,0 +1,7 @@ + LOAD PSGI + CREATE SERVICE psgi + SET role = web_server + SET listen = 127.0.0.1:80 + SET plugins = psgi + PSGI_APP = dev.localhost.localdomain.psgi + ENABLE psgi \ No newline at end of file diff --git a/etc/dev.localhost.localdomain.psgi b/etc/dev.localhost.localdomain.psgi index b40d87272..ae98f20df 100644 --- a/etc/dev.localhost.localdomain.psgi +++ b/etc/dev.localhost.localdomain.psgi @@ -1,49 +1,25 @@ -BEGIN { - # Define your site settings here - # These are the config values that normally appear in your wre's - # site.modperl.conf and site.modproxy.conf - our $WEBGUI_ROOT = '/data/WebGUI'; - our $WEBGUI_CONFIG = 'dev.localhost.localdomain'; - our $DOCUMENT_ROOT = '/data/domains/dev.localhost.localdomain/public'; -} -use lib "$WEBGUI_ROOT/lib"; -#use local::lib $WEBGUI_ROOT; -use WebGUI; use Plack::Builder; - -my %SETTINGS = ( - 'wg.WEBGUI_ROOT' => $WEBGUI_ROOT, - 'wg.WEBGUI_CONFIG' => "$WEBGUI_CONFIG.conf", - 'wg.DOCUMENT_ROOT' => $DOCUMENT_ROOT, - 'wg.DIR_CONFIG.WebguiRoot' => $WEBGUI_ROOT, - 'wg.DIR_CONFIG.WebguiConfig' => "$WEBGUI_CONFIG.conf", -); - -my $wg = sub { - my $env = shift; - @{$env}{ keys %SETTINGS } = values %SETTINGS; - WebGUI::handle_psgi($env); -}; +use lib '/data/WebGUI/lib'; +use WebGUI; builder { + + # Populate $env from site.conf + add 'Plack::Middleware::WebGUI', + root => '/data/WebGUI', + config => 'dev.localhost.localdomain.conf'; - # /extras - deliver via Plack::Middleware::Static + # 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', path => qr{^/extras/}, - root => "$SETTINGS{'wg.WEBGUI_ROOT'}/www/"; + root => '/data/WebGUI/www'; - # /uploads - deliver via Plack::Middleware::WGAccess - # This takes the place of WebGUI::URL::Uploads in handling .wgaccess and - # delivery of static files in /uploads + # 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', path => qr{^/uploads/}, - settings => {%SETTINGS}; + root => '/data/domains/dev.localhost.localdomain/public'; - add 'Plack::Middleware::XFramework', framework => 'WebGUI'; - - # AccessLog already enabled by default if you are using the plackup script - # add 'Plack::Middleware::AccessLog', - # format => "combined"; - - $wg; + sub { WebGUI::handle_psgi(shift) }; } diff --git a/lib/Plack/Middleware/WGAccess.pm b/lib/Plack/Middleware/WGAccess.pm index ce7b71228..8c289cfba 100644 --- a/lib/Plack/Middleware/WGAccess.pm +++ b/lib/Plack/Middleware/WGAccess.pm @@ -3,7 +3,6 @@ use strict; use warnings; use base qw/Plack::Middleware::Static/; use Path::Class 'dir'; -__PACKAGE__->mk_accessors('settings'); =head1 NAME @@ -17,13 +16,6 @@ Plack Middleware that delivers static files with .wgaccess awareness sub _handle_static { my($self, $env) = @_; - - # Populate $env with $self->settings so that we get consistent wg API behaviour - my %settings = %{$self->settings}; - @{$env}{keys %settings} = values %settings; - - # Populate $self->root from $SETTINGS so that it doesn't need to be specified in psgi file - $self->root($settings{'wg.DOCUMENT_ROOT'}); ####################################### # Copied from Plack::Middleware::Static::_handle_static diff --git a/lib/Plack/Middleware/WebGUI.pm b/lib/Plack/Middleware/WebGUI.pm new file mode 100644 index 000000000..defa4eda5 --- /dev/null +++ b/lib/Plack/Middleware/WebGUI.pm @@ -0,0 +1,30 @@ +package Plack::Middleware::WebGUI; +use strict; +use warnings; +use base qw/Plack::Middleware/; + +__PACKAGE__->mk_accessors('root', 'config'); + +=head1 NAME + +Plack::Middleware::WebGUI + +=head1 DESCRIPTION + +Plack Middleware that populates $env + +In the future we might want to read the site.conf here and then cache it + +=cut + +sub call { + my $self = shift; + my $env = shift; + + $env->{'wg.WEBGUI_ROOT'} = $self->root; + $env->{'wg.WEBGUI_CONFIG'} = $self->config; + + $self->app->($env); +} + +1; \ No newline at end of file diff --git a/lib/WebGUI/Session/Plack.pm b/lib/WebGUI/Session/Plack.pm index bf4672193..3446718cf 100644 --- a/lib/WebGUI/Session/Plack.pm +++ b/lib/WebGUI/Session/Plack.pm @@ -39,23 +39,24 @@ sub AUTOLOAD { } # Emulate/delegate/fake Apache2::* subs -sub uri { shift->{request}->request_uri(@_) } -sub param { shift->{request}->param(@_) } -sub params { shift->{request}->params(@_) } -sub headers_in { shift->{request}->headers(@_) } -sub headers_out { shift->{headers_out} } -sub protocol { shift->{request}->protocol(@_) } -sub status { shift->{response}->status(@_) } -sub sendfile { $_[0]->{sendfile} = $_[1] } -sub server { shift->{server} } -sub method { shift->{request}->method } -sub upload { shift->{request}->upload(@_) } -sub status_line { } -sub auth_type { } # should we support this? -sub handler { 'perl-script' } # or not..? +sub uri { shift->{request}->request_uri(@_) } +sub param { shift->{request}->param(@_) } +sub params { shift->{request}->params(@_) } +sub headers_in { shift->{request}->headers(@_) } +sub headers_out { shift->{headers_out} } +sub protocol { shift->{request}->protocol(@_) } +sub status { shift->{response}->status(@_) } +sub sendfile { $_[0]->{sendfile} = $_[1] } +sub server { shift->{server} } +sub method { shift->{request}->method } +sub upload { shift->{request}->upload(@_) } +sub dir_config { shift->{server}->dir_config(@_) } +sub status_line { } +sub auth_type { } # should we support this? +sub handler {'perl-script'} # or not..? -sub content_type { - my ($self, $ct) = @_; +sub content_type { + my ( $self, $ct ) = @_; $self->{headers_out}->set( 'Content-Type' => $ct ); } @@ -82,11 +83,6 @@ sub print { push @{ $self->{body} }, @_; } -sub dir_config { - my ( $self, $c ) = @_; - return $self->{env}->{"wg.DIR_CONFIG.$c"}; -} - sub pnotes { my ( $self, $key ) = ( shift, shift ); return wantarray ? %{ $self->{pnotes} } : $self->{pnotes} unless defined $key; @@ -162,6 +158,12 @@ sub AUTOLOAD { 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'; + + # Otherwise, we might want to provide some sort of support (which Apache is still around) return $self->{env}->{"wg.DIR_CONFIG.$c"}; }