Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should "Cro Endpoint HTTP" be defined?

Tags:

raku

cro

The console shows this this message after starting cro ('cro run'):

ā–¶ Starting JoanPujol (JoanPujol)
šŸ”Œ **Endpoint HTTP will be at http://localhost:20000/**
šŸ““ JoanPujol Listening at http://localhost:3000
šŸ““ JoanPujol Shutting down...
ā™» Restarting JoanPujol (JoanPujol)
šŸ““ JoanPujol Listening at http://localhost:3000

I have not been able to figure out where "Endpoint HTTP" is defined. This is my 'service.p6':

use Cro::HTTP::Log::File;
use Cro::HTTP::Server;
use Routes;

constant HOST = 'localhost';
constant PORT = 3000;

my Cro::Service $http = Cro::HTTP::Server.new(
    :http<1.1>,
    host => HOST, 
    port => PORT,
    application => routes(),
    after => [
      Cro::HTTP::Log::File.new(logs => $*OUT, errors => %*ERR)
    ]
);
$http.start;
say "Listening at http://{HOST}:{PORT}";
react {
    whenever signal(SIGINT) {
        say "Shutting down...";
        $http.stop;
        done;
    }
}

Thanks!

like image 774
Mimosinnet Avatar asked Jul 07 '18 21:07

Mimosinnet


1 Answers

The cro development tool automatically picks a free port for each endpoint in each service it is asked to run. When there are multiple services and they have links between them specified, it also injects the selected ports through environment variables to the dependent services. This makes it possible to set up a bunch of services that can have their ports configured via environment variables, and then have cro run assign a port to each of them and spread that information, so that the services can communicate with each other.

The message is indicating which port number was automatically selected. However, since the service script just overrides those anyway, it has no effect. To disable this functionality and get rid of the message, remove the endpoint list entry in the .cro.yml file.

If wishing to hardcode the port into the service script, then it's probably easier to declare them with constant rather than using %*ENV.

like image 83
Jonathan Worthington Avatar answered Dec 25 '22 00:12

Jonathan Worthington