diff options
author | dakkar <dakkar@thenautilus.net> | 2017-12-17 19:09:31 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2017-12-17 19:09:31 +0000 |
commit | ba1caee706c51e25a6ee325f4c338aa4d2d31292 (patch) | |
tree | 28d041597203df828bf1e8f3cab631213006d877 /lib/Ultramarine/Controller.pm6 | |
parent | passes "connection test" from official Android app! (diff) | |
download | Ultramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.tar.gz Ultramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.tar.bz2 Ultramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.zip |
split pieces into modules
Diffstat (limited to 'lib/Ultramarine/Controller.pm6')
-rw-r--r-- | lib/Ultramarine/Controller.pm6 | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Ultramarine/Controller.pm6 b/lib/Ultramarine/Controller.pm6 new file mode 100644 index 0000000..29433fd --- /dev/null +++ b/lib/Ultramarine/Controller.pm6 @@ -0,0 +1,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(), + } + } +} |