Bug 26456: Reindent MARC subfield structure template
[koha.git] / Koha / App / Intranet.pm
blobbf66e9e62bac3e3d4d7bf8ea135159cc0cdb679a
1 package Koha::App::Intranet;
3 # Copyright 2020 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Mojo::Base 'Mojolicious';
24 use Koha::Caches;
25 use Koha::Cache::Memory::Lite;
27 sub startup {
28 my ($self) = @_;
30 push @{$self->plugins->namespaces}, 'Koha::App::Plugin';
31 push @{$self->static->paths}, $self->home->rel_file('koha-tmpl');
33 # Create route for all CGI scripts, need to be loaded first because of
34 # CGI::Compile
35 $self->plugin('CGIBinKoha');
37 # Create routes for API
38 # FIXME This generates routes like this: /api/api/v1/...
39 $self->plugin('RESTV1');
41 $self->hook(before_dispatch => \&_before_dispatch);
42 $self->hook(around_action => \&_around_action);
44 my $r = $self->routes;
46 $r->any('/')->to(cb => sub { shift->redirect_to('/cgi-bin/koha/mainpage.pl') });
49 sub _before_dispatch {
50 my $c = shift;
52 my $path = $c->req->url->path->to_string;
54 # Remove Koha version from URL
55 $path =~ s/_\d{2}\.\d{7}\.(js|css)/.$1/;
57 # See FIXME above
58 if ($path =~ m|^/api/v|) {
59 $path = '/api' . $path;
62 $c->req->url->path->parse($path);
65 sub _around_action {
66 my ($next, $c, $action, $last) = @_;
68 # Flush memory caches before every request
69 Koha::Caches->flush_L1_caches();
70 Koha::Cache::Memory::Lite->flush();
72 return $next->();
77 =encoding utf8
79 =head1 NAME
81 Koha::App::Intranet - Mojolicious app for Koha's Intranet Client
83 =head1 DESCRIPTION
85 Run the Koha Intranet using Mojolicious servers
87 =head1 METHODS
89 =head2 startup
91 Called at application startup; Sets up routes, loads plugins and invokes hooks.
93 =cut