File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed
lib/MetaCPAN/Web/Controller Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ RUN <<EOT
2222 npm run build:min
2323EOT
2424
25+ HEALTHCHECK CMD [ "test" , "-e" , "root/assets/assets.json" ]
26+
2527# ################## Web Server
2628# hadolint ignore=DL3007
2729FROM metacpan/metacpan-base:latest AS server
@@ -62,6 +64,8 @@ CMD [ \
6264
6365EXPOSE 80
6466
67+ HEALTHCHECK --start-period=3s CMD [ "curl" , "--fail" , "http://localhost/healthcheck" ]
68+
6569# ################## Development Server
6670FROM server AS develop
6771
Original file line number Diff line number Diff line change @@ -93,6 +93,16 @@ sub robots : Path("robots.txt") : Args(0) {
9393 } );
9494}
9595
96+ sub healthcheck : Local : Args(0) {
97+ my ( $self , $c ) = @_ ;
98+
99+ $c -> res-> content_type(' application/json' );
100+ $c -> stash( {
101+ template => ' healthcheck.tx' ,
102+ status => ' healthy' ,
103+ } );
104+ }
105+
96106=head2 end
97107
98108Attempt to render a view, if needed.
Original file line number Diff line number Diff line change 1+ [% { status => $status }.json() | raw %]
Original file line number Diff line number Diff line change 1+ use strict;
2+ use warnings;
3+ use lib ' t/lib' ;
4+
5+ use Cpanel::JSON::XS qw( decode_json ) ;
6+ use MetaCPAN::Web::Test qw( app GET test_psgi ) ;
7+ use Test::More;
8+
9+ test_psgi app, sub {
10+ my $cb = shift ;
11+ ok( my $res = $cb -> ( GET ' /healthcheck' ), ' GET /healthcheck' );
12+ is( $res -> code, 200, ' code 200' );
13+ is $res -> header(' Content-Type' ), ' application/json' ,
14+ ' correct Content-Type' ;
15+ my $data = decode_json( $res -> content );
16+ is $data -> {status }, ' healthy' , ' has correct status' ;
17+ };
18+
19+ done_testing;
You can’t perform that action at this time.
0 commit comments