]> Sergey Matveev's repositories - public-inbox.git/blobdiff - examples/public-inbox.psgi
examples/public-inbox.psgi: optional deflater
[public-inbox.git] / examples / public-inbox.psgi
index 6d8fd24c49a0c8b2e511bb3cfcb191a4fc45e892..b0b9ae9850bd9620937a15dff753df152588d0df 100644 (file)
@@ -1,12 +1,25 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
+# Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
 # Note: this is part of our test suite, update t/plack.t if this changes
+# Usage: plackup [OPTIONS] /path/to/this/file
 use strict;
 use warnings;
-require PublicInbox::WWW;
-require Plack::Request;
-sub {
-       my $req = Plack::Request->new(@_);
-       PublicInbox::WWW::run($req, $req->method);
-};
+use PublicInbox::WWW;
+PublicInbox::WWW->preload;
+use Plack::Request;
+use Plack::Builder;
+my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
+
+builder {
+       if ($have_deflater) {
+               enable "Deflater",
+                       content_type => [ 'text/html', 'text/plain',
+                                       'application/atom+xml' ];
+       }
+       enable "Head";
+       sub {
+               my $req = Plack::Request->new(@_);
+               PublicInbox::WWW::run($req, $req->method);
+       }
+}