forked from andk/pause
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_2017.psgi
80 lines (64 loc) · 2.34 KB
/
app_2017.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
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib/", "$FindBin::Bin/lib/pause_2017", "$FindBin::Bin/../pause-private/lib", "$FindBin::Bin/privatelib";
use Plack::Builder;
use Plack::App::Directory::Apaxy;
use Path::Tiny;
my $AppRoot = path(__FILE__)->parent->realpath;
Log::Dispatch::Config->configure("$AppRoot/etc/plack_log.conf.".($ENV{PLACK_ENV} // 'development'));
$ENV{MOJO_REVERSE_PROXY} = 1;
$ENV{MOJO_HOME} = $AppRoot;
# preload stuff
use PAUSE::Web::Context;
use PAUSE::Web;
use PAUSE::Web::App::Index;
use PAUSE::Web::App::Disabled;
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 $builder = eval {
my $context = PAUSE::Web::Context->new(root => $AppRoot);
$context->init;
my $pause_app = PAUSE::Web->new(pause => $context);
my $index_app = PAUSE::Web::App::Index->new->to_app;
my $disabled_app = PAUSE::Web::App::Disabled->new->to_app;
builder {
enable 'LogDispatch', logger => $context->logger;
enable 'ReverseProxy';
enable 'ServerStatus::Tiny', path => '/status';
if (-f "/etc/PAUSE.CLOSED") {
mount '/' => builder { $disabled_app };
} else {
# 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::Web::Middleware::Auth::Basic', context => $context;
Plack::App::Directory::Apaxy->new(root => $PAUSE::Config->{FTPPUB});
};
mount '/incoming' => builder {
enable '+PAUSE::Web::Middleware::Auth::Basic', context => $context;
Plack::App::Directory::Apaxy->new(root => $PAUSE::Config->{INCOMING_LOC});
};
mount '/pause' => builder {
enable_if {$_[0]->{PATH_INFO} =~ /authenquery/ ? 1 : 0} '+PAUSE::Web::Middleware::Auth::Basic', context => $context;
$pause_app->start('psgi');
};
mount '/' => builder { $index_app };
}
};
};
if ($@) {
Log::Dispatch::Config->instance->log(
level => 'error',
message => "$@",
);
}
$builder;