summaryrefslogtreecommitdiff
path: root/lib/Ultramarine/Controller.pm6
blob: 29433fd95368dcb5610077a2721ee2f53a7e5b26 (plain)
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
use v6.d.PREVIEW;
use Cro::HTTP::Router;
 
class Ultramarine::Controller {
    has $.license is required;
    has $.authorisation is required;
 
    sub respond(*@body{
        response.status = 200;
        response.set-body(@body);
    }
 
    submethod inner-routes() {
        return route {
            # this needs to be here, not in the Server because its 
            # short-circuited "unauthorised" response will be emited 
            # in an 'after' middleware, but the 
            # ResponseSerializerExtension is applied just before those 
            # middlewares, so our serialised won't be seen by the 
            # "unauthorised" response 
            before $!authorisation;
            post -> 'ping.view' { respond [] }
            post -> 'getLicense.view' {
                respond [ license => [ |%($!license.status) ] ],
            }
        }
    }
 
    method routes() {
        return route {
            include rest => self.inner-routes(),
        }
    }
}