Skip to content

Commit 9a84ef7

Browse files
authored
Merge pull request #1315 from metacpan/haarg/favicon
add favicon.ico
2 parents ff78f4c + 123f0be commit 9a84ef7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app.psgi

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ use File::Path ();
1313
use File::Spec ();
1414
use Log::Log4perl ();
1515
use Path::Tiny qw( path );
16+
use Plack::App::File ();
1617
use Plack::App::Directory ();
1718
use Plack::App::URLMap ();
19+
use Plack::Util ();
1820

1921
my $dev_mode;
2022
my $config;
@@ -55,11 +57,40 @@ if ( -e "/.dockerenv" and MetaCPAN::Server->log->isa('Catalyst::Log') ) {
5557
STDOUT->autoflush;
5658
}
5759

60+
sub _add_headers {
61+
my ( $app, $add_headers ) = @_;
62+
sub {
63+
Plack::Util::response_cb(
64+
$app->(@_),
65+
sub {
66+
my $res = shift;
67+
my ( $status, $headers ) = @$res;
68+
if ( $status >= 200 && $status < 300 ) {
69+
push @$headers, @$add_headers;
70+
}
71+
return $res;
72+
}
73+
);
74+
};
75+
}
76+
5877
my $static
5978
= Plack::App::Directory->new(
6079
{ root => path( $root_dir, 'root', 'static' ) } )->to_app;
6180

6281
my $urlmap = Plack::App::URLMap->new;
82+
$urlmap->map(
83+
'/favicon.ico' => _add_headers(
84+
Plack::App::File->new(
85+
file => path( $root_dir, 'root', 'static', 'favicon.ico' )
86+
)->to_app,
87+
[
88+
'Cache-Control' => 'public, max-age=' . ( 60 * 60 * 24 ),
89+
'Surrogate-Control' => 'max-age=' . ( 60 * 60 * 24 * 365 ),
90+
'Surrogate-Key' => 'static',
91+
],
92+
)
93+
);
6394
$urlmap->map( '/static' => $static );
6495
if ( $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development' ) {
6596
$urlmap->map( '/v1' => MetaCPAN::Server->app );

root/static/favicon.ico

17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)