@@ -2,9 +2,11 @@ package com.devsisters.shardcake
22
33import caliban .ZHttpAdapter
44import caliban .wrappers .Wrappers .printErrors
5+ import com .devsisters .shardcake .interfaces .Logging
56import zhttp .http .Middleware .cors
67import zhttp .http ._
7- import zhttp .service .{ Server => ZServer }
8+ import zhttp .service .{ EventLoopGroup , Server => ZServer }
9+ import zhttp .service .server .ServerChannelFactory
810import zio ._
911import zio .clock .Clock
1012import zio .console .Console
@@ -14,18 +16,23 @@ object Server {
1416 /**
1517 * Start an HTTP server that exposes the Shard Manager GraphQL API
1618 */
17- val run : RIO [Has [ShardManager ] with Has [ManagerConfig ] with Clock with Console , Nothing ] =
19+ val run : RIO [Has [ShardManager ] with Has [ManagerConfig ] with Has [ Logging ] with Clock with Console , Nothing ] =
1820 for {
1921 config <- ZIO .service[ManagerConfig ]
22+ logger <- ZIO .service[Logging ]
2023 interpreter <- (GraphQLApi .api @@ printErrors).interpreter
21- nothing <- ZServer
22- .start(
23- config.apiPort,
24- Http .collectHttp[Request ] {
25- case _ -> !! / " health" => Http .succeed(Response .ok)
26- case _ -> !! / " api" / " graphql" => ZHttpAdapter .makeHttpService(interpreter)
27- case _ -> !! / " ws" / " graphql" => ZHttpAdapter .makeWebSocketService(interpreter)
28- } @@ cors()
24+ server = ZServer .port(config.apiPort) ++ ZServer .app(Http .collectHttp[Request ] {
25+ case _ -> !! / " health" => Http .succeed(Response .ok)
26+ case _ -> !! / " api" / " graphql" => ZHttpAdapter .makeHttpService(interpreter)
27+ case _ -> !! / " ws" / " graphql" => ZHttpAdapter .makeWebSocketService(interpreter)
28+ } @@ cors())
29+ nothing <- server.make
30+ .use(start =>
31+ logger.logInfo(s " Server Manager started on port ${start.port}" )
32+ *> ZIO .never
33+ )
34+ .provideSomeLayer[Console with Has [ShardManager ] with Clock ](
35+ ServerChannelFactory .auto ++ EventLoopGroup .auto(0 )
2936 )
3037 .forever
3138 } yield nothing
0 commit comments