Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 88 lines (81 sloc) 2.484 kb
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
package MetaCPAN::Web;

# ABSTRACT: Modern front-end for MetaCPAN

use strict;
use warnings;

BEGIN {
    if ( $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development' ) {
        $ENV{PLACK_SERVER} = 'Standalone';
        $ENV{METACPAN_WEB_DEBUG} = 1;
    }
}

use FindBin;
use lib "$FindBin::RealBin/lib";
use File::Path ();
use MetaCPAN::Web;
use Plack::App::File;
use Plack::App::URLMap;
use Plack::Middleware::Assets;
use Plack::Middleware::Runtime;
use Plack::Middleware::ReverseProxy;
use Plack::Middleware::Session::Cookie;
use Plack::Middleware::ServerStatus::Lite;

my $app = Plack::App::URLMap->new;
$app->map( '/static/' => Plack::App::File->new( root => 'root/static' ) );
$app->map( '/favicon.ico' =>
        Plack::App::File->new( file => 'root/static/icons/favicon.ico' ) );
$app->map( '/' => MetaCPAN::Web->psgi_app );
my $scoreboard = "$FindBin::RealBin/var/tmp/scoreboard";
unless (-d $scoreboard) {
    File::Path::make_path($scoreboard) or die "Can't make_path $scoreboard: $!";
}
$app = Plack::Middleware::ServerStatus::Lite->wrap(
   $app,
   path => '/server-status',
   allow => ['127.0.0.1'],
   scoreboard => $scoreboard,
) unless $0 =~ /\.t$/;
$app = Plack::Middleware::Runtime->wrap($app);
$app = Plack::Middleware::Assets->wrap( $app,
    files => [<root/static/css/*.css>] );
$app = Plack::Middleware::Assets->wrap(
    $app,

# should we autoload the syntax brushes or otherwise specify which ones are needed (instead of "all")?
    files => [
        map {"root/static/js/$_.js"}
            qw(
jquery.min
jquery.tablesorter
jquery.cookie
jquery.relatize_date
jquery.ajaxQueue
jquery.qtip.pack
jquery.autocomplete.pack
shCore
shBrushPerl
shBrushPlain
shBrushYaml
shBrushJScript
shBrushDiff
shBrushCpp
shBrushCPANChanges
cpan
github
)
    ],
);

Plack::Middleware::ReverseProxy->wrap(
    sub {
        my $env = shift;
        my $secure = $env->{'HTTP_X_FORWARDED_PORT'}
            && $env->{'HTTP_X_FORWARDED_PORT'} eq '443';
        Plack::Middleware::Session::Cookie->wrap(
            $app,
            session_key => $secure
            ? 'metacpan_secure'
            : 'metacpan',
            expires => 2**30,
            $secure ? ( secure => 1 ) : (),
            httponly => 1,
        )->($env);
    }
);
Something went wrong with that request. Please try again.