]> Sergey Matveev's repositories - public-inbox.git/blob - examples/newswww.psgi
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / examples / newswww.psgi
1 #!/usr/bin/perl -w
2 # Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 #
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://")
10 #
11 # Usage:
12 #       plackup -I lib -o 127.0.0.1 -R lib -r examples/newswww.psgi
13 use strict;
14 use warnings;
15 use Plack::Builder;
16 use PublicInbox::WWW;
17 use PublicInbox::NewsWWW;
18
19 my $newswww = PublicInbox::NewsWWW->new;
20
21 # Optional, (you may drop the "mount '/'" section below)
22 my $www = PublicInbox::WWW->new;
23 $www->preload;
24
25 builder {
26         # HTTP/1.1 requests to "Host: news.example.com" will hit this:
27         mount 'http://news.example.com/' => builder {
28                 enable 'Head';
29                 sub { $newswww->call($_[0]) };
30         };
31
32         # rest of requests will hit this (optional) part for the
33         # regular PublicInbox::WWW code:
34         # see comments in examples/public-inbox.psgi for more info:
35         mount '/' => builder {
36                 eval {
37                         enable 'Deflater',
38                                 content_type => [ qw(
39                                         text/html
40                                         text/plain
41                                         application/atom+xml
42                                         )]
43                 };
44                 eval { enable 'ReverseProxy' };
45                 enable 'Head';
46                 sub { $www->call($_[0]) }
47         };
48 }