X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=examples%2Fpublic-inbox.psgi;h=e97f917fbe8bdd46a3569f982bdde0212ae91cfc;hb=5e14b8e68483ab412b4a3ae1a62429237143b89b;hp=dcca3b09a3e1e30b324c32dfb1f5edb876b71184;hpb=997e3033e58dfd101d5e5bb7491c609fde75099f;p=public-inbox.git diff --git a/examples/public-inbox.psgi b/examples/public-inbox.psgi index dcca3b09..e97f917f 100644 --- a/examples/public-inbox.psgi +++ b/examples/public-inbox.psgi @@ -9,11 +9,13 @@ use strict; use warnings; use PublicInbox::WWW; PublicInbox::WWW->preload; -use Plack::Request; use Plack::Builder; my $www = PublicInbox::WWW->new; + +# share the public-inbox code itself: +my $src = $ENV{SRC_GIT_DIR}; # '/path/to/public-inbox.git' + builder { - enable 'Chunked'; eval { enable 'Deflater', content_type => [ qw( @@ -27,7 +29,7 @@ builder { # Enable to ensure redirects and Atom feed URLs are generated # properly when running behind a reverse proxy server which - # sets X-Forwarded-For and X-Forwarded-Proto request headers. + # sets the X-Forwarded-Proto request header. # See Plack::Middleware::ReverseProxy documentation for details eval { enable 'ReverseProxy' }; $@ and warn @@ -42,5 +44,15 @@ builder { # format => '%t "%r" %>s %b %D'; enable 'Head'; - sub { $www->call(@_) }; + sub { + my ($env) = @_; + # share public-inbox.git code! + if ($src && $env->{PATH_INFO} =~ + m!\A/(?:public-inbox(?:\.git)?/)? + ($PublicInbox::GitHTTPBackend::ANY)\z!xo) { + PublicInbox::GitHTTPBackend::serve($env, $src, $1); + } else { + $www->call($env); + } + }; }