Skip to content

Instantly share code, notes, and snippets.

@ziguzagu
Created March 6, 2013 05:40
Show Gist options
  • Save ziguzagu/5097003 to your computer and use it in GitHub Desktop.
Save ziguzagu/5097003 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use FindBin;
use MogileFS::Client;
use Plack::Builder;
use Plack::MIME;
my $mog;
my $app = sub {
my $env = shift;
$mog = MogileFS::Client->new(
domain => 'brad',
hosts => [ 'mog01', 'mog02' ]
) or die $@;
my $key = $env->{PATH_INFO};
$key .= 'index.html' if $key =~ m{/$};
my @urls = $mog->get_paths($key)
or return [ '404', [], [] ];
my %header = (
'X-REPROXY-URL' => join(' ', @urls),
'X-REPROXY-CACHE-FOR' => '86400; Content-Type',
'Content-Type' => Plack::MIME->mime_type($key),
);
return [ 200, [ %header ], [] ];
};
builder {
enable 'ErrorDocument',
404 => "$FindBin::Bin/htdocs/error/404.html";
enable 'DefaultDocument',
'/favicon\.ico$' => "$FindBin::Bin/htdocs/favicon.ico";
$app;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment