7ff4c251236fb37a9d88bf84b59cfa9499e283cf
[koha.git] / app.psgi
1 #!/usr/bin/perl
2
3 use CGI::Compile;
4 use CGI::Emulate::PSGI;
5 use Plack::App::URLMap;
6 use Plack::App::Directory;
7
8 use lib '/srv/koha';
9 my $app = Plack::App::URLMap->new;
10
11 my $from = '/srv/koha/opac';
12 my $to   = '/cgi-bin/koha';
13
14 foreach my $script ( glob "$from/*" ) {
15         my $path = $script;
16         $path =~ s{^$from}{} || die;
17         $path =~ s{^/+}{};
18
19         my $sub = eval { CGI::Compile->compile($script) };
20
21         if ( $@ ) {
22                 warn "ERROR: can't compile $script: $@";
23                 next;
24         }
25
26         my $cgi_app = CGI::Emulate::PSGI->handler($sub);
27         $app->mount( "$to/$path" => $cgi_app );
28         warn "# script $script -> $to/$path";
29 }
30
31 $app->mount( '/' => Plack::App::Directory->new( { root => '/srv/koha/koha-tmpl/' } )->to_app );
32
33 $app;