Somewhat proper cli interface

This commit is contained in:
Adam Ruzicka 2023-04-28 17:34:47 +02:00
parent 8f7f4918ee
commit 4f0c334e12
2 changed files with 26 additions and 12 deletions

View File

@ -1,10 +1,22 @@
#!/usr/bin/env raku
constant ROOT = ".".IO.absolute;
constant DOMAIN = "touched-mammal.lxd.test";
use Ramini;
use Ramini::Logger;
use Ramini::Server;
Ramini::Server.new(root => ROOT.IO, domain => DOMAIN).run()
sub MAIN(
Str :$certificate-file, #= Path to SSL server certificate
Str :$private-key-file, #= Path to SSL private key
Str :$server-name, #= Hostname to serve content for, requests to other names will be rejected
Str :$root = ".", #= Root directory to serve content from
Int :$port = 1965, #= Port to listen on
Str :$listen = '::' #= Address to listen on
) {
Ramini::Server.new(
domain => $server-name,
:$listen,
:$port,
root => $root.IO.absolute,
:$certificate-file,
:$private-key-file
).run()
}

View File

@ -5,21 +5,23 @@ use Ramini::Logger;
unit class Ramini::Server;
has IO::Path $.root;
has Int $.port;
has Str $.listen;
has Str $.root;
has Str $.domain;
method run() {
my %ssl-config =
certificate-file => 'cert.pem',
private-key-file => 'key.pem';
has Str $.certificate-file is required;
has Str $.private-key-file is required;
my $connections = IO::Socket::Async::SSL.listen('::', 4433, |%ssl-config);
method run() {
my $connections = IO::Socket::Async::SSL.listen($!listen, $!port, :$.certificate-file, :$.private-key-file);
react {
my $listener = do whenever $connections -> $socket {
start self!handle-connection($socket)
}
say "Server listening on port 4433";
say "Server listening on port " ~ $!port;
whenever signal(SIGINT) {
say "Shutting down...";