Bug 27068: Control hold group logic in HoldsQueue
[koha.git] / debian / templates / plack.psgi
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 use Modern::Perl;
19
20 use Plack::Builder;
21 use Plack::App::CGIBin;
22 use Plack::App::Directory;
23 use Plack::App::URLMap;
24 use Plack::Request;
25
26 use Mojo::Server::PSGI;
27
28 # Pre-load libraries
29 use C4::Boolean;
30 use C4::Koha;
31 use C4::Languages;
32 use C4::Letters;
33 use C4::Members;
34 use C4::XSLT;
35 use Koha::Caches;
36 use Koha::Cache::Memory::Lite;
37 use Koha::Database;
38 use Koha::DateUtils;
39 use Koha::Logger;
40
41 use Log::Log4perl;
42 use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
43 {
44     no warnings 'redefine';
45     my $old_new = \&CGI::new;
46     *CGI::new = sub {
47         my $q = $old_new->( @_ );
48         $CGI::PARAM_UTF8 = 1;
49         Koha::Caches->flush_L1_caches();
50         Koha::Cache::Memory::Lite->flush();
51         return $q;
52     };
53 }
54
55 my $home = $ENV{KOHA_HOME};
56 my $intranet = Plack::App::CGIBin->new(
57     root => $ENV{DEV_INSTALL}? $home: "$home/intranet/cgi-bin"
58 )->to_app;
59
60 my $opac = Plack::App::CGIBin->new(
61     root => $ENV{DEV_INSTALL}? "$home/opac": "$home/opac/cgi-bin/opac"
62 )->to_app;
63
64 my $apiv1  = builder {
65     my $server = Mojo::Server::PSGI->new;
66     $server->load_app("$home/api/v1/app.pl");
67     $server->to_psgi_app;
68 };
69
70 Koha::Logger->_init;
71
72 builder {
73     enable "ReverseProxy";
74     enable "Plack::Middleware::Static";
75
76     # + is required so Plack doesn't try to prefix Plack::Middleware::
77     enable "+Koha::Middleware::SetEnv";
78     enable "+Koha::Middleware::RealIP";
79
80     mount '/opac'          => builder {
81         #NOTE: it is important that these are relative links
82         enable 'ErrorDocument',
83             400 => 'errors/400.pl',
84             401 => 'errors/401.pl',
85             402 => 'errors/402.pl',
86             403 => 'errors/403.pl',
87             404 => 'errors/404.pl',
88             500 => 'errors/500.pl',
89             subrequest => 1;
90         #NOTE: Without this middleware to catch fatal errors, ErrorDocument won't be able to render a 500 document
91         #NOTE: This middleware must be closer to the PSGI app than ErrorDocument
92         enable "HTTPExceptions";
93         if ( Log::Log4perl->get_logger('plack-opac')->has_appenders ){
94             enable 'Log4perl', category => 'plack-opac';
95             enable 'LogWarn';
96         }
97         $opac;
98     };
99     mount '/intranet'      => builder {
100         #NOTE: it is important that these are relative links
101         enable 'ErrorDocument',
102             400 => 'errors/400.pl',
103             401 => 'errors/401.pl',
104             402 => 'errors/402.pl',
105             403 => 'errors/403.pl',
106             404 => 'errors/404.pl',
107             500 => 'errors/500.pl',
108             subrequest => 1;
109         #NOTE: Without this middleware to catch fatal errors, ErrorDocument won't be able to render a 500 document
110         #NOTE: This middleware must be closer to the PSGI app than ErrorDocument
111         enable "HTTPExceptions";
112         if ( Log::Log4perl->get_logger('plack-intranet')->has_appenders ){
113             enable 'Log4perl', category => 'plack-intranet';
114             enable 'LogWarn';
115         }
116         $intranet;
117     };
118     mount '/api/v1/app.pl' => builder {
119         if ( Log::Log4perl->get_logger('plack-api')->has_appenders ){
120             enable 'Log4perl', category => 'plack-api';
121             enable 'LogWarn';
122         }
123         $apiv1;
124     };
125 };