2 # Copyright (C) 2016-2020 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.
7 use PublicInbox::Daemon;
9 for (qw(Plack::Builder Plack::Util)) {
10 eval("require $_") or die "E: Plack is required for $0\n";
12 Plack::Builder->import;
13 require PublicInbox::HTTP;
14 require PublicInbox::HTTPD;
20 eval { $app = Plack::Util::load_psgi(@ARGV) };
23 "$0 runs in /, command-line paths must be absolute\n";
26 require PublicInbox::WWW;
27 my $www = PublicInbox::WWW->new;
30 eval { enable 'ReverseProxy' };
32 "Plack::Middleware::ReverseProxy missing,\n",
33 "URL generation for redirects may be wrong if behind a reverse proxy\n";
36 sub { $www->call(@_) };
41 PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
42 sub ($$$) { # post_accept
43 my ($client, $addr, $srv) = @_;
44 my $fd = fileno($srv);
45 my $h = $httpds{$fd} ||= PublicInbox::HTTPD->new($srv, $app);
46 PublicInbox::HTTP->new($client, $addr, $h),