forked from metacpan/metacpan-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.psgi
129 lines (117 loc) · 3.35 KB
/
app.psgi
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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::MCLess;
use Plack::Middleware::ReverseProxy;
use Plack::Middleware::Session::Cookie;
use Plack::Middleware::ServerStatus::Lite;
# explicitly call ->to_app on every Plack::App::* for performance
my $app = Plack::App::URLMap->new;
$app->map(
'/static/' => Plack::App::File->new( root => 'root/static' )->to_app );
$app->map( '/favicon.ico' =>
Plack::App::File->new( file => 'root/static/icons/favicon.ico' )
->to_app );
$app->map( '/' => MetaCPAN::Web->psgi_app );
$app = $app->to_app;
unless ( $ENV{HARNESS_ACTIVE} ) {
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,
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
toolbar
github
contributors
dropdown
bootstrap/bootstrap-dropdown
bootstrap/bootstrap-collapse
bootstrap/bootstrap-modal
bootstrap/bootstrap-tooltip
bootstrap-slidepanel
)
],
);
use CHI;
if ( !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} ne 'development' ) {
# Only need for live
my $cache = CHI->new(
driver => 'File',
root_dir => '/tmp/less.cache'
);
# Wrap up to serve lessc parsed files
$app = Plack::Middleware::MCLess->wrap(
$app,
cache => $cache,
cache_ttl => "60 minutes",
root => "root/static",
files => [
map {"root/static/less/$_.less"}
qw(
style
)
],
);
}
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);
}
);