@@ -18,6 +18,7 @@ use Config::JFDI;
18
18
use FindBin;
19
19
use lib " $FindBin::RealBin /lib" ;
20
20
use File::Path ();
21
+ use JSON qw( encode_json decode_json ) ;
21
22
use MetaCPAN::Web;
22
23
use Plack::Builder;
23
24
use Plack::App::File;
@@ -29,6 +30,7 @@ use Plack::Middleware::MCLess;
29
30
use Plack::Middleware::ReverseProxy;
30
31
use Plack::Middleware::Session::Cookie;
31
32
use Plack::Middleware::ServerStatus::Lite;
33
+ use Plack::Session::Store::File;
32
34
33
35
# explicitly call ->to_app on every Plack::App::* for performance
34
36
my $app = Plack::App::URLMap-> new;
@@ -63,6 +65,9 @@ my $app = Plack::App::URLMap->new;
63
65
64
66
die ' cookie_secret not configured' unless $config -> get-> {cookie_secret };
65
67
68
+ my $storage_path = " $path /var/tmp/cookies" ;
69
+ maybe_make_path($storage_path );
70
+
66
71
# Add session cookie here only
67
72
$core_app = Plack::Middleware::Session::Cookie-> wrap(
68
73
$core_app ,
@@ -71,6 +76,11 @@ my $app = Plack::App::URLMap->new;
71
76
secure => ( ( $ENV {PLACK_ENV } || q[ ] ) ne ' development' ),
72
77
httponly => 1,
73
78
secret => $config -> get-> {cookie_secret },
79
+ store => Plack::Session::Store::File-> new(
80
+ dir => $storage_path ,
81
+ serializer => sub { encode_json(@_ ) },
82
+ deserializer => sub { decode_json(@_ ) },
83
+ ),
74
84
);
75
85
76
86
$app -> map ( q[ /] => $core_app );
@@ -80,10 +90,8 @@ $app = $app->to_app;
80
90
81
91
unless ( $ENV {HARNESS_ACTIVE } ) {
82
92
my $scoreboard = " $FindBin::RealBin /var/tmp/scoreboard" ;
83
- unless ( -d $scoreboard ) {
84
- File::Path::make_path($scoreboard )
85
- or die " Can't make_path $scoreboard : $! " ;
86
- }
93
+ maybe_make_path($scoreboard );
94
+
87
95
$app = Plack::Middleware::ServerStatus::Lite-> wrap(
88
96
$app ,
89
97
path => ' /server-status' ,
@@ -175,6 +183,14 @@ if ( !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} ne 'development' ) {
175
183
};
176
184
}
177
185
186
+ sub maybe_make_path {
187
+ my $path = shift ;
188
+
189
+ return if -d $path ;
190
+
191
+ File::Path::make_path($path ) or die " Can't make_path $path : $! " ;
192
+ }
193
+
178
194
$app = Plack::Middleware::ReverseProxy-> wrap($app );
179
195
180
196
return $app ;
0 commit comments