forked from croservices/cro-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.p6
39 lines (37 loc) · 1.02 KB
/
service.p6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use Cro::HTTP::Log::File;
use Cro::HTTP::Server;
use Cro::Transform;
use Routes;
class CacheHeader does Cro::Transform {
method consumes() { Cro::HTTP::Response }
method produces() { Cro::HTTP::Response }
method transformer(Supply $responses --> Supply) {
supply {
whenever $responses {
.append-header('Cache-control', 'public, max-age=60');
.emit;
}
}
}
}
my Cro::Service $http = Cro::HTTP::Server.new(
http => '1.1',
host => %*ENV<CRO_WEBSITE_HOST> ||
die("Missing CRO_WEBSITE_HOST in environment"),
port => %*ENV<CRO_WEBSITE_PORT> ||
die("Missing CRO_WEBSITE_PORT in environment"),
application => routes(),
after => [
CacheHeader,
Cro::HTTP::Log::File.new(logs => $*OUT, errors => $*ERR)
]
);
$http.start;
say "Listening at http://%*ENV<CRO_WEBSITE_HOST>:%*ENV<CRO_WEBSITE_PORT>";
react {
whenever signal(SIGINT) {
say "Shutting down...";
$http.stop;
done;
}
}