-
Notifications
You must be signed in to change notification settings - Fork 259
/
app.psgi
65 lines (55 loc) · 1.76 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
# Copyright 2020 BibLibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use FindBin;
use Plack::Builder;
use Mojo::Server::PSGI;
sub psgi_app {
my ($script) = @_;
my $server = Mojo::Server::PSGI->new;
$server->load_app("$FindBin::Bin/$script");
return $server->to_psgi_app;
}
my $opac = psgi_app('bin/opac');
my $intranet = psgi_app('bin/intranet');
my $opac_port = $ENV{KOHA_OPAC_PORT} || 5001;
my $intranet_port = $ENV{KOHA_INTRANET_PORT} || 5000;
my $port2app = {
$opac_port => $opac,
$intranet_port => $intranet,
};
builder {
# This middleware decides which app to run (opac or intranet) depending on
# SERVER_PORT. It must be run before ReverseProxy middleware which can
# modify SERVER_PORT
enable sub {
my $app = shift;
sub {
my $env = shift;
$env->{'koha.app'} = $port2app->{$env->{SERVER_PORT}} || $intranet;
return $app->($env);
}
};
enable 'ReverseProxy';
enable '+Koha::Middleware::UserEnv';
enable '+Koha::Middleware::SetEnv';
enable '+Koha::Middleware::RealIP';
sub {
my $env = shift;
$env->{'koha.app'}->($env);
};
}