2 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Standalone HTTP server for public-inbox.
8 use PublicInbox::Daemon;
10 for (qw(Plack::Builder Plack::Util)) {
11 eval("require $_") or die "E: Plack is required for $0\n";
13 Plack::Builder->import;
14 require PublicInbox::HTTP;
15 require PublicInbox::HTTPD;
18 my %httpds; # per-listen-FD mapping for HTTPD->{env}->{SERVER_<NAME|PORT>}
22 eval { $app = Plack::Util::load_psgi(@ARGV) };
25 "$0 runs in /, command-line paths must be absolute\n";
28 require PublicInbox::WWW;
29 my $www = PublicInbox::WWW->new;
32 eval { enable 'ReverseProxy' };
34 "Plack::Middleware::ReverseProxy missing,\n",
35 "URL generation for redirects may be wrong if behind a reverse proxy\n";
38 sub { $www->call(@_) };
41 %httpds = (); # invalidate cache
44 PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
45 sub ($$$) { # Listener->{post_accept}
46 my ($client, $addr, $srv, $tls_wrap) = @_;
47 my $fd = fileno($srv);
48 my $h = $httpds{$fd} //=
49 PublicInbox::HTTPD->new($srv, $app, $client);
50 PublicInbox::HTTP->new($client, $addr, $h),