forked from andk/pause
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.psgi
82 lines (68 loc) · 2.38 KB
/
app.psgi
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use Plack::Builder;
use Plack::Request;
use Plack::App::Directory::Apaxy;
use Log::Dispatch::Config;
Log::Dispatch::Config->configure("$FindBin::Bin/etc/plack_log.conf.".($ENV{PLACK_ENV} // 'development'));
# preload stuff
use pause_1999::config;
use pause_1999::index;
use pause_1999::fixup;
use perl_pause::disabled2;
use BSD::Resource ();
#BSD::Resource::setrlimit(BSD::Resource::RLIMIT_CPU(),
# 60*10, 60*10);
#BSD::Resource::setrlimit(BSD::Resource::RLIMIT_DATA(),
# 40*1024*1024, 40*1024*1024);
BSD::Resource::setrlimit(BSD::Resource::RLIMIT_CORE(),
40*1024*1024, 40*1024*1024);
my $pause_app = sub {
my $req = Plack::Request->new(shift);
if (-f "/etc/PAUSE.CLOSED") {
return perl_pause::disabled2::handler($req);
}
my $res =
pause_1999::fixup::handler($req) //
pause_1999::config::handler($req);
return $res if ref $res;
[$res =~ /^\d+$/ ? $res : 500, [], [$res]];
};
my $index_app = sub {
my $req = Plack::Request->new(shift);
my $res = pause_1999::index::handler($req);
return $res if ref $res;
[$res =~ /^\d+$/ ? $res : 500, [], [$res]];
};
builder {
enable 'LogDispatch', logger => Log::Dispatch::Config->instance;
# enable 'AccessLog::Timed', format => 'combined';
enable 'ReverseProxy';
# enable_if {$_[0]->{REMOTE_ADDR} eq '127.0.0.1'} 'ReverseProxy';
# enable 'ErrorDocument',
# 500 => '',
# 404 => '',
# 403 => '',
# ;
enable 'ServerStatus::Tiny', path => '/status';
# Static files are serverd by us; maybe some day we want to change that
enable 'Static',
path => qr{(?:(?<!index)\.(js|css|gif|jpg|png|pod|html)$|^/\.well-known/)},
root => "$FindBin::Bin/htdocs";
mount '/pub/PAUSE' => builder {
enable '+PAUSE::Middleware::Auth::Basic';
Plack::App::Directory::Apaxy->new(root => $PAUSE::Config->{FTPPUB});
};
mount '/incoming' => builder {
enable '+PAUSE::Middleware::Auth::Basic';
Plack::App::Directory::Apaxy->new(root => $PAUSE::Config->{INCOMING_LOC});
};
mount '/pause' => builder {
enable_if {$_[0]->{PATH_INFO} =~ /authenquery/ ? 1 : 0} '+PAUSE::Middleware::Auth::Basic';
$pause_app;
};
mount '/' => builder { $index_app };
};