import zio.http._
import zio.http.service.ServerChannelFactory
import zio.http.service.ServerSSLHandler._
import zio.http.service.{EventLoopGroup}
import zio._
object HttpsHelloWorld extends App {
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case Method.GET -> !! / "text" => Response.text("Hello World!")
case Method.GET -> !! / "json" => Response.json("""{"greetings": "Hello World!"}""")
}
val sslctx = ctxFromCert(
getClass().getClassLoader().getResourceAsStream("server.crt"),
getClass().getClassLoader().getResourceAsStream("server.key"),
)
private val server =
Server.port(8090) ++ Server.app(app) ++ Server.ssl(
ServerSSLOptions(sslctx, SSLHttpBehaviour.Accept),
)
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
server.make.useForever
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(0))
.exitCode
}
}