user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
blob 9b869f906032ed8e090f60d3c92ca62792ab47de 1577 bytes (raw)
name: script/public-inbox-httpd 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
#!/usr/bin/perl -w
# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Standalone HTTP server for public-inbox.
use strict;
use warnings;
use Plack::Util;
use PublicInbox::Daemon;
use PublicInbox::HTTP;
use PublicInbox::HTTPD;
use Plack::Builder;
my %httpds;
my $app;
my $refresh = sub {
	if (@ARGV) {
		eval { $app = Plack::Util::load_psgi(@ARGV) };
		if ($@) {
			die $@,
"$0 runs in /, command-line paths must be absolute\n";
		}
	} else {
		require PublicInbox::WWW;
		my $www = PublicInbox::WWW->new;
		$www->preload;
		$app = builder {
			# Perl 5.16.3 leaks in our "push" response code path
			# (e.g. Qspawn) due to something in
			# Plack::Util::response_cb, regardless of whether the
			# client is sending Accept-Encoding:gzip requests.
			# perl5180delta documents many leak fixes, so assume
			# 5.18+ is safe for now and bump the check as-need:
			$] >= 5.018000 and eval {
				enable 'Deflater',
					content_type => [ qw(
						text/html
						text/plain
						application/atom+xml
						)]
			};

			eval { enable 'ReverseProxy' };
			$@ and warn
"Plack::Middleware::ReverseProxy missing,\n",
"URL generation for redirects may be wrong if behind a reverse proxy\n";

			enable 'Head';
			sub { $www->call(@_) };
		};
	}
};

PublicInbox::Daemon::run('0.0.0.0:8080', $refresh,
	sub ($$$) { # post_accept
		my ($client, $addr, $srv) = @_;
		my $fd = fileno($srv);
		my $h = $httpds{$fd} ||= PublicInbox::HTTPD->new($srv, $app);
		PublicInbox::HTTP->new($client, $addr, $h),
	});

debug log:

solving 9b869f9 ...
`9b869f9' ambiguous in https://80x24.org/public-inbox.git
9b869f906032ed8e090f60d3c92ca62792ab47de blob
9b869f948675bf87157924c117b7b3352644d00a blob

found 9b869f9 in https://public-inbox.org/meta/20190926015038.29770-3-e@80x24.org/
found b2464f4 in https://80x24.org/public-inbox.git
preparing index
index prepared:
100755 b2464f4efc0d31be9909c872c3969353e33768c6	script/public-inbox-httpd

applying [1/1] https://public-inbox.org/meta/20190926015038.29770-3-e@80x24.org/
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index b2464f4..9b869f9 100755

Checking patch script/public-inbox-httpd...
Applied patch script/public-inbox-httpd cleanly.

index at:
100755 9b869f906032ed8e090f60d3c92ca62792ab47de	script/public-inbox-httpd

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).