Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (81 sloc) 2.484 kb
30c5f57 @monken add app.psgi
monken authored
1 package MetaCPAN::Web;
2
3 # ABSTRACT: Modern front-end for MetaCPAN
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
4
30c5f57 @monken add app.psgi
monken authored
5 use strict;
6 use warnings;
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
7
8 BEGIN {
cda7e42 @monken silence warning when testing
monken authored
9 if ( $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development' ) {
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
10 $ENV{PLACK_SERVER} = 'Standalone';
11 $ENV{METACPAN_WEB_DEBUG} = 1;
12 }
13 }
14
30c5f57 @monken add app.psgi
monken authored
15 use FindBin;
16 use lib "$FindBin::RealBin/lib";
5b62e0d @pjcj Create scoreboard dir if it doesn't exist.
pjcj authored
17 use File::Path ();
30c5f57 @monken add app.psgi
monken authored
18 use MetaCPAN::Web;
19 use Plack::App::File;
655e863 @monken P::M::StackTrace fucks with Catalyst
monken authored
20 use Plack::App::URLMap;
30c5f57 @monken add app.psgi
monken authored
21 use Plack::Middleware::Assets;
22 use Plack::Middleware::Runtime;
23 use Plack::Middleware::ReverseProxy;
e078289 @monken add Session::Cookie middleware
monken authored
24 use Plack::Middleware::Session::Cookie;
602e65e @monken add Plack::Middleware::ServerStatus::Lite
monken authored
25 use Plack::Middleware::ServerStatus::Lite;
30c5f57 @monken add app.psgi
monken authored
26
27 my $app = Plack::App::URLMap->new;
28 $app->map( '/static/' => Plack::App::File->new( root => 'root/static' ) );
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
29 $app->map( '/favicon.ico' =>
30 Plack::App::File->new( file => 'root/static/icons/favicon.ico' ) );
3e25517 @monken require latest Catalyst and get rid of Catalyst::Engine::PSGI
monken authored
31 $app->map( '/' => MetaCPAN::Web->psgi_app );
5b62e0d @pjcj Create scoreboard dir if it doesn't exist.
pjcj authored
32 my $scoreboard = "$FindBin::RealBin/var/tmp/scoreboard";
33 unless (-d $scoreboard) {
34 File::Path::make_path($scoreboard) or die "Can't make_path $scoreboard: $!";
35 }
602e65e @monken add Plack::Middleware::ServerStatus::Lite
monken authored
36 $app = Plack::Middleware::ServerStatus::Lite->wrap(
37 $app,
38 path => '/server-status',
39 allow => ['127.0.0.1'],
5b62e0d @pjcj Create scoreboard dir if it doesn't exist.
pjcj authored
40 scoreboard => $scoreboard,
b3f0236 @rafl Skip the ServerStatus middleware for tests
rafl authored
41 ) unless $0 =~ /\.t$/;
30c5f57 @monken add app.psgi
monken authored
42 $app = Plack::Middleware::Runtime->wrap($app);
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
43 $app = Plack::Middleware::Assets->wrap( $app,
44 files => [<root/static/css/*.css>] );
30c5f57 @monken add app.psgi
monken authored
45 $app = Plack::Middleware::Assets->wrap(
46 $app,
83bdb95 @monken minify javascript
monken authored
47
48 # should we autoload the syntax brushes or otherwise specify which ones are needed (instead of "all")?
30c5f57 @monken add app.psgi
monken authored
49 files => [
c8976c8 @monken enable catalyst debug when running with plackup
monken authored
50 map {"root/static/js/$_.js"}
83bdb95 @monken minify javascript
monken authored
51 qw(
52 jquery.min
53 jquery.tablesorter
54 jquery.cookie
55 jquery.relatize_date
56 jquery.ajaxQueue
57 jquery.qtip.pack
58 jquery.autocomplete.pack
59 shCore
60 shBrushPerl
61 shBrushPlain
62 shBrushYaml
63 shBrushJScript
64 shBrushDiff
c48be56 @rwstauner Syntax Highlight .c, .h, and .xss
rwstauner authored
65 shBrushCpp
aaeefc6 @rwstauner Add syntax highlighting for CPAN::Changes-style changelog
rwstauner authored
66 shBrushCPANChanges
83bdb95 @monken minify javascript
monken authored
67 cpan
68 github
69 )
30c5f57 @monken add app.psgi
monken authored
70 ],
71 );
72
39ae24d @monken use X_FORWARDED_PORT to distinguish between secure and unsecure connecti...
monken authored
73 Plack::Middleware::ReverseProxy->wrap(
74 sub {
e699800 @monken silence warning in dev env
monken authored
75 my $env = shift;
76 my $secure = $env->{'HTTP_X_FORWARDED_PORT'}
77 && $env->{'HTTP_X_FORWARDED_PORT'} eq '443';
39ae24d @monken use X_FORWARDED_PORT to distinguish between secure and unsecure connecti...
monken authored
78 Plack::Middleware::Session::Cookie->wrap(
79 $app,
80 session_key => $secure
81 ? 'metacpan_secure'
82 : 'metacpan',
83 expires => 2**30,
84 $secure ? ( secure => 1 ) : (),
85 httponly => 1,
86 )->($env);
87 }
b3f0236 @rafl Skip the ServerStatus middleware for tests
rafl authored
88 );
Something went wrong with that request. Please try again.