summaryrefslogtreecommitdiff
path: root/lib/Ultramarine/Server.pm
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2017-12-17 19:09:31 +0000
committerdakkar <dakkar@thenautilus.net>2017-12-17 19:09:31 +0000
commitba1caee706c51e25a6ee325f4c338aa4d2d31292 (patch)
tree28d041597203df828bf1e8f3cab631213006d877 /lib/Ultramarine/Server.pm
parentpasses "connection test" from official Android app! (diff)
downloadUltramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.tar.gz
Ultramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.tar.bz2
Ultramarine-ba1caee706c51e25a6ee325f4c338aa4d2d31292.zip
split pieces into modules
Diffstat (limited to 'lib/Ultramarine/Server.pm')
-rw-r--r--lib/Ultramarine/Server.pm46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/Ultramarine/Server.pm b/lib/Ultramarine/Server.pm
new file mode 100644
index 0000000..ec7220c
--- /dev/null
+++ b/lib/Ultramarine/Server.pm
@@ -0,0 +1,46 @@
+use v6.d.PREVIEW;
+use Cro::HTTP::Server;
+use Cro::HTTP::Request;
+use Cro::HTTP::Response;
+
+class Ultramarine::Server {
+ has $.authentication is required;
+ has @.serialisers is required;
+ has $.set-content-type is required;
+ has $.controller is required;
+ has $.host = 'localhost';
+ has $.port = 8080;
+ has $.do-trace = False;
+
+ my class Trace does Cro::Transform {
+ has $.type is required;
+
+ method consumes() { $!type }
+ method produces() { $!type }
+
+ method transformer(Supply $input --> Supply) {
+ supply whenever $input -> $thing {
+ say $thing.trace-output,"\n";
+ say (await $thing.body-text).indent(2);
+ emit $thing;
+ }
+ }
+ }
+
+ method server() {
+ return Cro::HTTP::Server.new(
+ :$!host,
+ :$!port,
+ application => $!controller,
+ before => [
+ $.do-trace ?? Trace.new(type=>Cro::HTTP::Request) !! (),
+ $.authentication,
+ ],
+ add-body-serializers => @.serialisers,
+ after => [
+ $.set-content-type,
+ $.do-trace ?? Trace.new(type=>Cro::HTTP::Response) !! (),
+ ],
+ );
+ }
+}