]> Sergey Matveev's repositories - public-inbox.git/blob - examples/public-inbox.psgi
git: allow cloning from the URL root, too
[public-inbox.git] / examples / public-inbox.psgi
1 #!/usr/bin/perl -w
2 # Copyright (C) 2014-2016 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 PublicInbox::WWW->preload;
12 use Plack::Builder;
13 my $www = PublicInbox::WWW->new;
14
15 # share the public-inbox code itself:
16 my $src = $ENV{SRC_GIT_DIR}; # '/path/to/public-inbox.git'
17
18 builder {
19         eval {
20                 enable 'Deflater',
21                         content_type => [ qw(
22                                 text/html
23                                 text/plain
24                                 application/atom+xml
25                                 )]
26         };
27         $@ and warn
28 "Plack::Middleware::Deflater missing, bandwidth will be wasted\n";
29
30         # Enable to ensure redirects and Atom feed URLs are generated
31         # properly when running behind a reverse proxy server which
32         # sets X-Forwarded-For and X-Forwarded-Proto request headers.
33         # See Plack::Middleware::ReverseProxy documentation for details
34         eval { enable 'ReverseProxy' };
35         $@ and warn
36 "Plack::Middleware::ReverseProxy missing,\n",
37 "URL generation for redirects may be wrong if behind a reverse proxy\n";
38
39         # Optional: Log timing information for requests to track performance.
40         # Logging to STDOUT is recommended since public-inbox-httpd knows
41         # how to reopen it via SIGUSR1 after log rotation.
42         # enable 'AccessLog::Timed',
43         #       logger => sub { syswrite(STDOUT, $_[0]) },
44         #       format => '%t "%r" %>s %b %D';
45
46         enable 'Head';
47         sub {
48                 my ($env) = @_;
49                 # share public-inbox.git code!
50                 if ($src && $env->{PATH_INFO} =~
51                                 m!\A/(?:public-inbox(?:\.git)?/)?
52                                 ($PublicInbox::GitHTTPBackend::ANY)\z!xo) {
53                         PublicInbox::GitHTTPBackend::serve($env, $src, $1);
54                 } else {
55                         $www->call($env);
56                 }
57         };
58 }