]> Sergey Matveev's repositories - public-inbox.git/blobdiff - examples/public-inbox.psgi
git: allow cloning from the URL root, too
[public-inbox.git] / examples / public-inbox.psgi
index 55c113e425ae0010e77c392f04a733c3d9485f20..11e2a6e73a51115db0442600bd96650804cdc176 100644 (file)
@@ -11,8 +11,11 @@ use PublicInbox::WWW;
 PublicInbox::WWW->preload;
 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(
@@ -41,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);
+               }
+       };
 }