Bug 16733: [Follow-up] Add $home to api path too
[koha.git] / debian / templates / plack.psgi
blob3538b9a5a1d5ab3209486eb793bb1f4c9ee45a83
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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/>.
18 use Modern::Perl;
20 use Plack::Builder;
21 use Plack::App::CGIBin;
22 use Plack::App::Directory;
23 use Plack::App::URLMap;
24 use Plack::Request;
26 use Mojo::Server::PSGI;
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;
40 use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
42 no warnings 'redefine';
43 my $old_new = \&CGI::new;
44 *CGI::new = sub {
45 my $q = $old_new->( @_ );
46 $CGI::PARAM_UTF8 = 1;
47 Koha::Caches->flush_L1_caches();
48 Koha::Cache::Memory::Lite->flush();
49 return $q;
53 my $home = $ENV{KOHA_HOME};
54 my $intranet = Plack::App::CGIBin->new(
55 root => $ENV{DEV_INSTALL}? $home: "$home/intranet/cgi-bin"
56 )->to_app;
58 my $opac = Plack::App::CGIBin->new(
59 root => $ENV{DEV_INSTALL}? "$home/opac": "$home/opac/cgi-bin/opac"
60 )->to_app;
62 my $apiv1 = builder {
63 my $server = Mojo::Server::PSGI->new;
64 $server->load_app("$home/api/v1/app.pl");
65 $server->to_psgi_app;
68 builder {
69 enable "ReverseProxy";
70 enable "Plack::Middleware::Static";
71 # + is required so Plack doesn't try to prefix Plack::Middleware::
72 enable "+Koha::Middleware::SetEnv";
74 mount '/opac' => $opac;
75 mount '/intranet' => $intranet;
76 mount '/api/v1/app.pl' => $apiv1;