Help language development. Donate to The Perl Foundation

cro cpan:JNTHN last updated on 2021-11-12

t/tools-services-test-dir/service1/service.p6
use Cro::HTTP::Router;
use Cro::HTTP::Server;
use Cro::HTTP::Log::File;

my $routes = route {
    get -> {
        content 'text/plain', 'Service 1 OK';
    }
}

my Cro::Service $http = Cro::HTTP::Server.new(
    http => '1.1',
    host => %*ENV<SERVICE1_HTTP_HOST> ||
        die("Missing SERVICE1_HTTP_HOST in environment"),
    port => %*ENV<SERVICE1_HTTP_PORT> ||
        die("Missing SERVICE1_HTTP_PORT in environment"),
    application => $routes,
    after => [
        Cro::HTTP::Log::File.new(logs => $*OUT, errors => $*ERR)
    ]
);
$http.start;
react {
    whenever signal(SIGINT) {
        $http.stop;
        done;
    }
}