]> Sergey Matveev's repositories - public-inbox.git/blob - examples/public-inbox.psgi
http: remove unnecessary delete
[public-inbox.git] / examples / public-inbox.psgi
1 #!/usr/bin/perl -w
2 # Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 # Note: this is part of our test suite, update t/plack.t if this changes
5 # Usage: plackup [OPTIONS] /path/to/this/file
6 # A startup command for development which monitors changes:
7 #       plackup -I lib -o 127.0.0.1 -R lib -r examples/public-inbox.psgi
8 use strict;
9 use warnings;
10 use PublicInbox::WWW;
11 use Plack::Builder;
12 my $www = PublicInbox::WWW->new;
13 $www->preload;
14
15 # share the public-inbox code itself:
16 my $src = $ENV{SRC_GIT_DIR}; # '/path/to/public-inbox.git'
17 $src = PublicInbox::Git->new($src) if defined $src;
18
19 builder {
20         eval {
21                 enable 'Deflater',
22                         content_type => [ qw(
23                                 text/html
24                                 text/plain
25                                 application/atom+xml
26                                 )]
27         };
28
29         # Enable to ensure redirects and Atom feed URLs are generated
30         # properly when running behind a reverse proxy server which
31         # sets the X-Forwarded-Proto request header.
32         # See Plack::Middleware::ReverseProxy documentation for details
33         eval { enable 'ReverseProxy' };
34         $@ and warn
35 "Plack::Middleware::ReverseProxy missing,\n",
36 "URL generation for redirects may be wrong if behind a reverse proxy\n";
37
38         # Optional: Log timing information for requests to track performance.
39         # Logging to STDOUT is recommended since public-inbox-httpd knows
40         # how to reopen it via SIGUSR1 after log rotation.
41         # enable 'AccessLog::Timed',
42         #       logger => sub { syswrite(STDOUT, $_[0]) },
43         #       format => '%t "%r" %>s %b %D';
44
45         enable 'Head';
46         sub {
47                 my ($env) = @_;
48                 # share public-inbox.git code!
49                 if ($src && $env->{PATH_INFO} =~
50                                 m!\A/(?:public-inbox(?:\.git)?/)?
51                                 ($PublicInbox::GitHTTPBackend::ANY)\z!xo) {
52                         PublicInbox::GitHTTPBackend::serve($env, $src, $1);
53                 } else {
54                         $www->call($env);
55                 }
56         };
57 }