Skip to content

Commit

Permalink
Ember (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect authored Apr 25, 2024
1 parent dd6c770 commit 2d6401f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ lazy val idealVotingServer = project
Dependencies.circeParser,
Dependencies.commonsLang,
Dependencies.emil,
Dependencies.http4sServerBlaze,
Dependencies.http4sServerEmber,
Dependencies.jackson,
Dependencies.liquibaseSlf4j,
Dependencies.logback,
Expand Down Expand Up @@ -157,7 +157,7 @@ lazy val commonSettings: List[Def.Setting[_]] = DecentScala.decentScalaSettings
moduleFilter(organization = "org.slf4j", name = "slf4j-api"),
),
missinglinkIgnoreDestinationPackages ++= List(
IgnoredPackage("java.sql"), // https://github.com/tpolecat/doobie/pull/1632
IgnoredPackage("jnr.unixsocket"),
IgnoredPackage("org.osgi.framework"),
),
// https://github.com/olafurpg/sbt-ci-release/issues/181
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<pattern>%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"} [%thread] %-5level %logger{36} - %msg [%X]%n</pattern>
</encoder>
</appender>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
package cz.idealiste.idealvoting.server

import com.comcast.ip4s.{Host, Port}
import cz.idealiste.idealvoting.server
import cz.idealiste.idealvoting.server.HttpServerBlaze.Config
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.server.Server
import zio.Config.Error
import zio._
import zio.config.magnolia._
import zio.interop.catz._

import scala.annotation.nowarn

final case class HttpServerBlaze(config: Config, httpApp: HttpApp) extends HttpServer {

lazy val server: RIO[Scope, Server] = ZIO.executorWith { executor =>
BlazeServerBuilder[Task]
.withExecutionContext(executor.asExecutionContext)
.bindHttp(config.port, config.host)
@nowarn("msg=implicitForAsync")
lazy val server: RIO[Scope, Server] =
EmberServerBuilder
.default[Task]
.withHost(config.host)
.withPort(config.port)
.withHttpApp(httpApp.httpApp)
.resource
.build
.toScopedZIO
}

}

object HttpServerBlaze {

private[server] val layer = ZLayer.fromFunction(apply _).map(_.prune[HttpServer])

final case class Config(host: String, port: Int)
final case class Config(host: Host, port: Port)

object Config {
private[server] val layer = ZLayer.fromZIO(ZIO.service[server.Config].map(_.httpServer))
private[Config] implicit lazy val hostDeriveConfig: DeriveConfig[Host] =
DeriveConfig[String].mapOrFail(s => Host.fromString(s).toRight(Error.InvalidData(Chunk(), s)))
private[Config] implicit lazy val portDeriveConfig: DeriveConfig[Port] =
DeriveConfig[String].mapOrFail(s => Port.fromString(s).toRight(Error.InvalidData(Chunk(), s)))
implicit lazy val configDescriptor: DeriveConfig[Config] =
DeriveConfig.getDeriveConfig[Config]
}
Expand Down
4 changes: 1 addition & 3 deletions ideal-voting-server/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
<appender-ref ref="STDOUT"/>
</root>

<logger name="🐳 [alpine/socat:1" level="WARN"/>
<logger name="🐳 [docker-compose]" level="WARN"/>
<logger name="🐳 [testcontainers/ryuk:0" level="WARN"/>
<logger name="com.github.dockerjava" level="WARN"/>
<logger name="org.testcontainers" level="WARN"/>
<logger name="tc" level="WARN"/>

</configuration>
3 changes: 1 addition & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ object Dependencies {
val commonsLang = "3.14.0"
val emil = "0.17.0"
val http4s = "0.23.26"
val http4sBlaze = "0.23.16"
val jackson = "2.17.0"
val liquibaseSlf4j = "5.0.0"
val logback = "1.5.6"
Expand Down Expand Up @@ -38,7 +37,7 @@ object Dependencies {
val http4sClient = "org.http4s" %% "http4s-client" % Versions.http4s
val http4sDsl = "org.http4s" %% "http4s-dsl" % Versions.http4s
val http4sServer = "org.http4s" %% "http4s-server" % Versions.http4s
val http4sServerBlaze = "org.http4s" %% "http4s-blaze-server" % Versions.http4sBlaze
val http4sServerEmber = "org.http4s" %% "http4s-ember-server" % Versions.http4s
val jackson = "com.fasterxml.jackson.core" % "jackson-databind" % Versions.jackson
val liquibaseSlf4j = "com.mattbertolini" % "liquibase-slf4j" % Versions.liquibaseSlf4j
val logback = "ch.qos.logback" % "logback-classic" % Versions.logback
Expand Down

0 comments on commit 2d6401f

Please sign in to comment.