summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2017-12-16 20:39:41 +0000
committerdakkar <dakkar@thenautilus.net>2017-12-16 20:39:41 +0000
commit335f1a25aeee0863f6b5c12d71459395eacb8747 (patch)
tree7c11ab402e0827a9f89c636c3bcd22d94603f828
parentalso JSON serialiser (diff)
downloadUltramarine-335f1a25aeee0863f6b5c12d71459395eacb8747.tar.gz
Ultramarine-335f1a25aeee0863f6b5c12d71459395eacb8747.tar.bz2
Ultramarine-335f1a25aeee0863f6b5c12d71459395eacb8747.zip
nicer application / server structure
-rw-r--r--bin/ultramarine27
1 files changed, 20 insertions, 7 deletions
diff --git a/bin/ultramarine b/bin/ultramarine
index b98c358..b01527c 100644
--- a/bin/ultramarine
+++ b/bin/ultramarine
@@ -7,6 +7,7 @@ use Ultramarine::Middleware::Authentication;
use Ultramarine::Middleware::Authorisation;
use Ultramarine::Middleware::SetContentType;
use Ultramarine::Serialiser::XML;
+use Ultramarine::Serialiser::JSON;
sub respond(*@body) {
response.status = 200;
@@ -18,24 +19,36 @@ my $users = Ultramarine::Model::Users.new(
);
my $ultramarine_rest = route {
- before Ultramarine::Middleware::Authentication.new(:$users);
+ # 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 Ultramarine::Middleware::Authorisation;
- after Ultramarine::Middleware::SetContentType;
-
get -> 'ping.view' { respond [] }
};
my $ultramarine = route {
+ include rest => $ultramarine_rest;
+}
- body-serializer Ultramarine::Serialiser::XML.new;
- delegate <rest *> => $ultramarine_rest;
-}
my Cro::Service $um = Cro::HTTP::Server.new(
- :host<localhost>,
+ :host<192.168.1.145>,
:port<8080>,
application => $ultramarine,
+ before => [
+ Ultramarine::Middleware::Authentication.new(:$users),
+ ],
+ add-body-serializers => [
+ Ultramarine::Serialiser::XML,
+ Ultramarine::Serialiser::JSON,
+ ],
+ after => [
+ Ultramarine::Middleware::SetContentType,
+ ],
+
);
$um.start;