Async-Microservice
view release on metacpan or search on metacpan
lib/Async/Microservice.pm view on Meta::CPAN
# Route exists but method not supported
my @allowed = grep { defined $match->{mapping}->{$_} }
keys %{ $match->{mapping} };
return $this_req->respond(
405,
[ "Allow" => join( ", ", sort @allowed ) ],
'method not allowed'
);
}
}
return $this_req->respond( 404, [],
'path ' . $sub_path_info . ' not found' );
};
return sub {
my $respond = shift;
my $response = try {
$plack_handler_sub->($respond);
}
catch {
$this_req->respond( 503, [], 'internal server error: ' . $_ );
lib/Async/MicroserviceReq.pm view on Meta::CPAN
my $static_file = $self->static_dir->file($file_name)->stringify;
my $content_type = Plack::MIME->mime_type($static_file) || 'text/plain';
return await _fetch_file_ft($static_file)->then(
sub {
my ($content) = @_;
$content = $content_cb->($content) if $content_cb;
return [ 200, [ 'Content-Type' => $content_type ], $content ];
}
)->catch(
sub {
return [ 404, [@no_cache_headers], 'no such static file' ];
}
);
}
sub _fetch_file_ft {
my ($file) = @_;
my $aio_load_f = Future->new;
$aio_load_f->retain;
aio_load(
t/01_Async-Microservice.t view on Meta::CPAN
is( $mech->status, 405, 'method not allowed returns 405' );
is( $mech->res->header('allow'),
'GET', 'method not allowed returns allow header' );
};
subtest '/static' => sub {
$mech->get_ok(
$service_url . 'static/async-microservice-time_openapi.yaml',
'get OpenAPI config' );
$mech->get( $service_url . 'static/non-existing-file' );
is( $mech->status, 404, 'non-existing file returns 404' );
};
subtest 'OpenAPI' => sub {
note($service_url);
$mech->get_ok($service_url);
$mech->content_contains( '<div id="swagger-ui">',
'OpenAPI documentation in /' ) or return;
$mech->content_contains( '<title>OpenAPI - asmi-helloworld</title>',
'OpenAPI documentation updated' );
$mech->get_ok( $service_url . 'edit' );
( run in 0.999 second using v1.01-cache-2.11-cpan-39bf76dae61 )