summary refs log tree commit diff stats
path: root/server/service.raku
blob: 00d1c513a3967d3e1504f9b554f75398943011a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use Cro::HTTP::Server;
use Cro::HTTP::Router;
use Cro::HTTP::Log::File;

unit sub MAIN(
    Bool :$debug = True, #= enable debug mode
);

my $application = route {
    post -> 'new' {
        request-body -> (:$name) {

        }
    }

    # Serving static assets.
    get -> 'js', *@path { static 'dist/js', @path; }
    get -> 'css', *@path { static 'dist/css', @path; }
    get -> 'img', *@path { static 'dist/img', @path; }
    get -> 'fonts', *@path { static 'dist/fonts', @path; }

    # Serve the app on all paths, it'll handle the routing.
    get -> *@path {
        static 'dist/index.html';
    }
};

my $host = "0.0.0.0";
my $port = 9090;

my Cro::Service $http = Cro::HTTP::Server.new(
    http => <1.1>,
    host => $host,
    port => $port,
    :$application,
    after => [
              Cro::HTTP::Log::File.new(logs => $*OUT, errors => $*ERR)
          ]
);
$http.start;
put "Listening at http://{$host}:{$port}";

react {
    whenever signal(SIGINT) {
        say "Shutting down...";
        $http.stop;
        done;
    }
}