forked from metacpan/metacpan-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.psgi
66 lines (53 loc) · 1.63 KB
/
app.psgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use strict;
use warnings;
use File::Basename ();
my $root_dir;
BEGIN {
$root_dir = File::Basename::dirname(__FILE__);
}
use lib "$root_dir/lib";
use Config::ZOMG;
use File::Path ();
use File::Spec ();
use Log::Log4perl ();
use Path::Tiny qw( path );
use Plack::App::Directory ();
use Plack::App::URLMap ();
my $dev_mode;
my $config;
BEGIN {
$dev_mode = $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development';
$config = Config::ZOMG->open(
name => 'MetaCPAN::Server',
path => $root_dir,
);
if ($dev_mode) {
$ENV{METACPAN_SERVER_DEBUG} = 1;
if ( !$ENV{EMAIL_SENDER_TRANSPORT} ) {
$ENV{EMAIL_SENDER_TRANSPORT} = 'Maildir';
File::Path::mkpath( $ENV{EMAIL_SENDER_TRANSPORT_dir}
= "$root_dir/var/tmp/mail" );
}
}
my $log4perl_config
= File::Spec->rel2abs( $config->{log4perl_file} || 'log4perl.conf',
$root_dir );
Log::Log4perl::init($log4perl_config);
package MetaCPAN::Server::WarnHandler;
Log::Log4perl->wrapper_register(__PACKAGE__);
my $logger = Log::Log4perl->get_logger;
$SIG{__WARN__} = sub { $logger->warn(@_) };
}
use MetaCPAN::Server;
STDERR->autoflush;
# prevent output buffering when in Docker containers (e.g. in docker-compose)
if ( -e "/.dockerenv" and MetaCPAN::Server->log->isa('Catalyst::Log') ) {
STDOUT->autoflush;
}
my $static
= Plack::App::Directory->new(
{ root => path( $root_dir, 'root', 'static' ) } )->to_app;
my $urlmap = Plack::App::URLMap->new;
$urlmap->map( '/static' => $static );
$urlmap->map( '/' => MetaCPAN::Server->app );
return $urlmap->to_app;