diff options
Diffstat (limited to 'bin/ultramarine')
-rw-r--r-- | bin/ultramarine | 27 |
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; |