-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.psgi
70 lines (51 loc) · 1.95 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
use strict;
use warnings;
use lib 'lib';
use YourNextMP;
use YourNextMP::AutoCRUD;
use YourNextMP::Schema::YourNextMPDB::ResultSet::Image;
use Plack::Builder;
YourNextMP->setup_engine('PSGI');
my $ynmp_app = sub { YourNextMP->run(@_) };
YourNextMP::AutoCRUD->setup_engine('PSGI');
my $autocrud_app = sub { YourNextMP::AutoCRUD->run(@_) };
# Set up the auth
my $user_and_pass = YourNextMP->config->{'auth_basic_user_pass'};
my $authenticator = sub {
my $username = shift;
my $password = shift;
my ( $u_wanted, $p_wanted ) = split /:/, $user_and_pass, 2;
return $username eq $u_wanted && $password eq $p_wanted;
};
builder {
mount '/extra' => builder {
enable_if { $user_and_pass } "Plack::Middleware::Auth::Basic",
realm => YourNextMP->config->{'auth_basic_realm'},
authenticator => $authenticator;
# If request is from localhost then must be from a proxy
enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1'; }
"Plack::Middleware::ReverseProxy";
$autocrud_app;
};
mount '/' => builder {
enable_if { $user_and_pass } "Plack::Middleware::Auth::Basic",
realm => YourNextMP->config->{'auth_basic_realm'},
authenticator => $authenticator;
enable "Plack::Middleware::Deflater",
content_type => [ 'text/css', 'text/html', 'application/javascript' ],
vary_user_agent => 1;
# If request is from localhost then must be from a proxy
enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1'; }
"Plack::Middleware::ReverseProxy";
# enable 'Plack::Middleware::Debug';
enable "Plack::Middleware::Static",
path => qr{^/static/},
root => 'root/';
my $images_root =
YourNextMP::Schema::YourNextMPDB::ResultSet::Image->store_dir;
enable "Plack::Middleware::Static",
path => qr{^/images/},
root => "$images_root";
$ynmp_app;
};
};