Main Koha release repository https://koha-community.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.7 KiB

  1. # Copyright 2020 BibLibre
  2. #
  3. # This file is part of Koha.
  4. #
  5. # Koha is free software; you can redistribute it and/or modify it
  6. # 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. # Koha is distributed in the hope that it will be useful, but
  11. # 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 Koha; if not, see <http://www.gnu.org/licenses>.
  17. use Modern::Perl;
  18. use FindBin;
  19. use Plack::Builder;
  20. use Mojo::Server::PSGI;
  21. sub psgi_app {
  22. my ($script) = @_;
  23. my $server = Mojo::Server::PSGI->new;
  24. $server->load_app("$FindBin::Bin/$script");
  25. return $server->to_psgi_app;
  26. }
  27. my $opac = psgi_app('bin/opac');
  28. my $intranet = psgi_app('bin/intranet');
  29. my $opac_port = $ENV{KOHA_OPAC_PORT} || 5001;
  30. my $intranet_port = $ENV{KOHA_INTRANET_PORT} || 5000;
  31. my $port2app = {
  32. $opac_port => $opac,
  33. $intranet_port => $intranet,
  34. };
  35. builder {
  36. # This middleware decides which app to run (opac or intranet) depending on
  37. # SERVER_PORT. It must be run before ReverseProxy middleware which can
  38. # modify SERVER_PORT
  39. enable sub {
  40. my $app = shift;
  41. sub {
  42. my $env = shift;
  43. $env->{'koha.app'} = $port2app->{$env->{SERVER_PORT}} || $intranet;
  44. return $app->($env);
  45. }
  46. };
  47. enable 'ReverseProxy';
  48. enable '+Koha::Middleware::SetEnv';
  49. enable '+Koha::Middleware::RealIP';
  50. sub {
  51. my $env = shift;
  52. $env->{'koha.app'}->($env);
  53. };
  54. }