summaryrefslogtreecommitdiff
path: root/bin/ultramarine
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ultramarine')
-rw-r--r--bin/ultramarine46
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/ultramarine b/bin/ultramarine
new file mode 100644
index 0000000..b98c358
--- /dev/null
+++ b/bin/ultramarine
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl6
+use v6.d.PREVIEW;
+use Cro::HTTP::Router;
+use Cro::HTTP::Server;
+use Ultramarine::Model::Users;
+use Ultramarine::Middleware::Authentication;
+use Ultramarine::Middleware::Authorisation;
+use Ultramarine::Middleware::SetContentType;
+use Ultramarine::Serialiser::XML;
+
+sub respond(*@body) {
+ response.status = 200;
+ response.set-body(@body);
+}
+
+my $users = Ultramarine::Model::Users.new(
+ accounts=>{me=>'sesame'},
+);
+
+my $ultramarine_rest = route {
+ before Ultramarine::Middleware::Authentication.new(:$users);
+ before Ultramarine::Middleware::Authorisation;
+ after Ultramarine::Middleware::SetContentType;
+
+ get -> 'ping.view' { respond [] }
+};
+
+my $ultramarine = route {
+
+ body-serializer Ultramarine::Serialiser::XML.new;
+
+ delegate <rest *> => $ultramarine_rest;
+}
+
+my Cro::Service $um = Cro::HTTP::Server.new(
+ :host<localhost>,
+ :port<8080>,
+ application => $ultramarine,
+);
+
+$um.start;
+
+react whenever signal(SIGINT) {
+ $um.stop;
+ exit;
+}