v2writable: done: force synchronous awaitpid
[public-inbox.git] / examples / newswww.psgi
blob44462dd311a078a14530807b0a7e02b5fa5ea7e0
1 #!/usr/bin/perl -w
2 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
5 # NewsWWW may be used independently of WWW. This can be useful
6 # for mapping HTTP/HTTPS requests to the hostname of an NNTP server
7 # to redirect users to the proper HTTP/HTTPS endpoint for a given
8 # inbox. NewsWWW exists because people (or software) can mishandle
9 # "nntp://" or "news://" URLs as "http://" (or "https://")
11 # Usage (development, with auto-reload):
12 # plackup -I lib -o 127.0.0.1 -R lib -r examples/newswww.psgi
14 # Usage (production, with public-inbox-httpd(1)):
15 # public-inbox-httpd [OPTIONS] /path/to/examples/newsww.psgi
16 use strict;
17 use warnings;
18 use Plack::Builder;
19 use PublicInbox::WWW;
20 use PublicInbox::NewsWWW;
22 my $newswww = PublicInbox::NewsWWW->new;
24 # Optional, (you may drop the "mount '/'" section below)
25 my $www = PublicInbox::WWW->new;
26 $www->preload;
28 builder {
29 # HTTP/1.1 requests to "Host: news.example.com" will hit this:
30 mount 'http://news.example.com/' => builder {
31 enable 'Head';
32 sub { $newswww->call($_[0]) };
35 # rest of requests will hit this (optional) part for the
36 # regular PublicInbox::WWW code:
37 # see comments in examples/public-inbox.psgi for more info:
38 mount '/' => builder {
39 eval { enable 'ReverseProxy' };
40 enable 'Head';
41 sub { $www->call($_[0]) }