/
HttpServerZ.scala
31 lines (26 loc) · 1.06 KB
/
HttpServerZ.scala
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
/*
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package org.knora.webapi.core
import zhttp.http.HttpApp
import zhttp.service.Server
import zio.ZLayer
import zio._
import org.knora.webapi.config.AppConfig
import org.knora.webapi.routing.admin.ProjectsRouteZ
import org.knora.webapi.slice.resourceinfo.api.ResourceInfoRoute
object HttpServerZ {
private val apiRoutes: URIO[ResourceInfoRoute with ProjectsRouteZ, HttpApp[Any, Nothing]] = for {
projectsRoute <- ZIO.service[ProjectsRouteZ].map(_.route)
riRoute <- ZIO.service[ResourceInfoRoute].map(_.route)
} yield projectsRoute ++ riRoute
val layer: ZLayer[ResourceInfoRoute with ProjectsRouteZ with AppConfig, Nothing, Unit] = ZLayer {
for {
port <- ZIO.service[AppConfig].map(_.knoraApi.externalZioPort)
routes <- apiRoutes
_ <- Server.start(port, routes).forkDaemon
_ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<")
} yield ()
}
}