Skip to content

Commit

Permalink
add favicon.ico
Browse files Browse the repository at this point in the history
Browsers will continue to request a favicon, so give them one.
  • Loading branch information
haarg committed Nov 5, 2024
1 parent fcd2c46 commit 123f0be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use File::Path ();
use File::Spec ();
use Log::Log4perl ();
use Path::Tiny qw( path );
use Plack::App::File ();
use Plack::App::Directory ();
use Plack::App::URLMap ();
use Plack::Util ();

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

sub _add_headers {
my ( $app, $add_headers ) = @_;
sub {
Plack::Util::response_cb(
$app->(@_),
sub {
my $res = shift;
my ( $status, $headers ) = @$res;
if ( $status >= 200 && $status < 300 ) {
push @$headers, @$add_headers;
}
return $res;
}
);
};
}

my $static
= Plack::App::Directory->new(
{ root => path( $root_dir, 'root', 'static' ) } )->to_app;

my $urlmap = Plack::App::URLMap->new;
$urlmap->map(
'/favicon.ico' => _add_headers(
Plack::App::File->new(
file => path( $root_dir, 'root', 'static', 'favicon.ico' )
)->to_app,
[
'Cache-Control' => 'public, max-age=' . ( 60 * 60 * 24 ),
'Surrogate-Control' => 'max-age=' . ( 60 * 60 * 24 * 365 ),
'Surrogate-Key' => 'static',
],
)
);
$urlmap->map( '/static' => $static );
if ( $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development' ) {
$urlmap->map( '/v1' => MetaCPAN::Server->app );
Expand Down
Binary file added root/static/favicon.ico
Binary file not shown.

0 comments on commit 123f0be

Please sign in to comment.