Skip to content

Commit

Permalink
add datacenters for mirrors.cpan.org to use
Browse files Browse the repository at this point in the history
  • Loading branch information
ranguard committed Jul 25, 2016
1 parent 83a3c30 commit 3b32ec3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/MetaCPAN/Web/Controller/Sysadmin/Datacenters.pm
@@ -0,0 +1,30 @@
package MetaCPAN::Web::Controller::Sysadmin::Datacenters;

use Moose;

BEGIN { extends 'MetaCPAN::Web::Controller' }


# This is used by http://mirrors.cpan.org/ fetch our
# datacenters and update the official CPAN list

sub list_datacenters : Path('list') : Args(0) GET {
my ( $self, $c) = @_;

# Fetch the data center info from fastly
# XXX: will not work unless you have the credentials
my $datacenters = $c->datacenters;

$c->add_surrogate_key('datacenters');
$c->cdn_cache_ttl( $c->cdn_times->{one_day} );
$c->res->header(
'Cache-Control' => 'max-age=' . $c->cdn_times->{one_day} );

$c->stash( { success => $datacenters } );
$c->detach( $c->view('JSON') );

}

__PACKAGE__->meta->make_immutable;

1;
9 changes: 9 additions & 0 deletions lib/MetaCPAN/Web/Role/Fastly.pm
Expand Up @@ -86,6 +86,15 @@ has 'cdn_times' => (
lazy_build => 1,
);

sub datacenters {
my ($c) = @_;
my $net_fastly = $c->_net_fastly();
return unless $net_fastly;

my $datacenters = $net_fastly->client->_get('/datacenters');
return $datacenters;
}

sub _build_cdn_times {
return {
one_hour => 3600,
Expand Down

0 comments on commit 3b32ec3

Please sign in to comment.