From 698f345f48cce10b5e1ace3477d738dab27ae47b Mon Sep 17 00:00:00 2001 From: Jens Halm <3116929+jenshalm@users.noreply.github.com> Date: Sat, 20 Aug 2022 19:12:27 +0100 Subject: [PATCH 1/3] bump http4s to 0.23.14 --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 4b51af381..cb7fbde0b 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -10,7 +10,7 @@ object Dependencies { val catsCore = "2.7.0" val catsEffect = "3.3.5" val fs2 = "3.2.7" - val http4s = "0.23.10" + val http4s = "0.23.14" val munit = "0.7.29" val munitCE3 = "1.0.7" From e5960b34a33e026768fc9f9bd705f68e09810885 Mon Sep 17 00:00:00 2001 From: Jens Halm <3116929+jenshalm@users.noreply.github.com> Date: Sat, 20 Aug 2022 19:13:14 +0100 Subject: [PATCH 2/3] Revert "Switch to Ember server" This reverts commit 747b0a9167a76960f202d07015391d970d1fac04. --- build.sbt | 2 +- .../src/main/scala/laika/webtool/Main.scala | 15 ++++++----- .../scala/laika/preview/ServerBuilder.scala | 26 +++++++++---------- .../scala/laika/sbt/LaikaPreviewConfig.scala | 13 +++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/build.sbt b/build.sbt index 97f8699a7..93c9522e8 100644 --- a/build.sbt +++ b/build.sbt @@ -71,7 +71,7 @@ val munitCE3 = "org.typelevel" %% "munit-cats-effect-3" % versions.mu val fop = "org.apache.xmlgraphics" % "fop" % versions.fop val http4s = Seq( "org.http4s" %% "http4s-dsl" % versions.http4s, - "org.http4s" %% "http4s-ember-server" % versions.http4s + "org.http4s" %% "http4s-blaze-server" % versions.http4s ) lazy val root = project.in(file(".")) diff --git a/demo/jvm/src/main/scala/laika/webtool/Main.scala b/demo/jvm/src/main/scala/laika/webtool/Main.scala index a7643eeef..dd1696ce4 100644 --- a/demo/jvm/src/main/scala/laika/webtool/Main.scala +++ b/demo/jvm/src/main/scala/laika/webtool/Main.scala @@ -18,10 +18,9 @@ package laika.webtool import cats.effect.{ExitCode, IO, IOApp, Resource} import cats.implicits._ -import com.comcast.ip4s._ import org.http4s.implicits._ import org.http4s.server.Server -import org.http4s.ember.server.EmberServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder /** * @author Jens Halm @@ -35,9 +34,11 @@ object Main extends IOApp { app.use(_ => IO.never).as(ExitCode.Success) val app: Resource[IO, Server] = - EmberServerBuilder.default[IO] - .withHost(host"0.0.0.0") - .withPort(port"8080") - .withHttpApp(service) - .build + for { + ctx <- Resource.eval(IO.executionContext) + server <- BlazeServerBuilder[IO](ctx) + .bindHttp(8080, "0.0.0.0") + .withHttpApp(service) + .resource + } yield server } diff --git a/preview/src/main/scala/laika/preview/ServerBuilder.scala b/preview/src/main/scala/laika/preview/ServerBuilder.scala index 323a72f1f..efb522193 100644 --- a/preview/src/main/scala/laika/preview/ServerBuilder.scala +++ b/preview/src/main/scala/laika/preview/ServerBuilder.scala @@ -21,7 +21,6 @@ import java.io.{File, PrintWriter, StringWriter} import cats.data.{Kleisli, OptionT} import cats.effect._ import cats.syntax.all._ -import com.comcast.ip4s._ import fs2.concurrent.Topic import laika.ast import laika.ast.DocumentType @@ -33,7 +32,7 @@ import org.http4s.dsl.Http4sDsl import org.http4s.{HttpApp, HttpRoutes, Request} import org.http4s.implicits._ import org.http4s.server.{Router, Server} -import org.http4s.ember.server.EmberServerBuilder +import org.http4s.blaze.server.BlazeServerBuilder import scala.concurrent.duration._ @@ -81,11 +80,10 @@ class ServerBuilder[F[_]: Async] (parser: Resource[F, TreeParser[F]], } private def createServer (httpApp: HttpApp[F]): Resource[F, Server] = - EmberServerBuilder.default[F] - .withPort(config.port) - .withHost(config.host) + BlazeServerBuilder[F] + .bindHttp(config.port, config.host) .withHttpApp(httpApp) - .build + .resource private def binaryRenderFormats = List(EPUB).filter(_ => config.includeEPUB) ++ @@ -133,8 +131,8 @@ object ServerBuilder { * @param isVerbose whether each served page and each detected file change should be logged (default false) * @param apiDir an optional API directory from which API documentation should be served (default None) */ -class ServerConfig private (val port: Port, - val host:Host, +class ServerConfig private (val port: Int, + val host:String, val pollInterval: FiniteDuration, val artifactBasename: String, val includeEPUB: Boolean, @@ -142,8 +140,8 @@ class ServerConfig private (val port: Port, val isVerbose: Boolean, val apiDir: Option[FilePath]) { - private def copy (newPort: Port = port, - newHost: Host = host, + private def copy (newPort: Int = port, + newHost: String = host, newPollInterval: FiniteDuration = pollInterval, newArtifactBasename: String = artifactBasename, newIncludeEPUB: Boolean = includeEPUB, @@ -154,11 +152,11 @@ class ServerConfig private (val port: Port, /** Specifies the port the server should run on (default 4242). */ - def withPort (port: Port): ServerConfig = copy(newPort = port) + def withPort (port: Int): ServerConfig = copy(newPort = port) /** Specifies the host the server should run on (default localhost). */ - def withHost(host:Host):ServerConfig = copy(newHost = host) + def withHost(host:String):ServerConfig = copy(newHost = host) /** Specifies the interval at which input file resources are polled for changes (default 1 second). */ @@ -195,9 +193,9 @@ class ServerConfig private (val port: Port, */ object ServerConfig { - val defaultPort: Port = port"4242" + val defaultPort: Int = 4242 - val defaultHost:Host = host"localhost" + val defaultHost:String = "localhost" val defaultPollInterval: FiniteDuration = 1.second diff --git a/sbt/src/main/scala/laika/sbt/LaikaPreviewConfig.scala b/sbt/src/main/scala/laika/sbt/LaikaPreviewConfig.scala index 4c0c4d89f..f455b3d04 100644 --- a/sbt/src/main/scala/laika/sbt/LaikaPreviewConfig.scala +++ b/sbt/src/main/scala/laika/sbt/LaikaPreviewConfig.scala @@ -16,7 +16,6 @@ package laika.sbt -import com.comcast.ip4s._ import laika.preview.ServerConfig import scala.concurrent.duration.FiniteDuration @@ -27,22 +26,22 @@ import scala.concurrent.duration.FiniteDuration * @param pollInterval the interval at which input file resources are polled for changes (default 3 seconds) * @param isVerbose whether each served page and each detected file change should be logged (default false) */ -class LaikaPreviewConfig (val port: Port, - val host:Host, +class LaikaPreviewConfig (val port: Int, + val host:String, val pollInterval: FiniteDuration, val isVerbose: Boolean) { - private def copy (newPort: Port = port, - newHost:Host = host, + private def copy (newPort: Int = port, + newHost:String = host, newPollInterval: FiniteDuration = pollInterval, newVerbose: Boolean = isVerbose): LaikaPreviewConfig = new LaikaPreviewConfig(newPort, newHost,newPollInterval, newVerbose) /** Specifies the port the server should run on (default 4242). */ - def withPort (port: Port): LaikaPreviewConfig = copy(newPort = port) + def withPort (port: Int): LaikaPreviewConfig = copy(newPort = port) - def withHost(host:Host):LaikaPreviewConfig = copy(newHost = host) + def withHost(host:String):LaikaPreviewConfig = copy(newHost = host) /** Specifies the interval at which input file resources are polled for changes (default 3 seconds). */ From 987883f306b7a39b7ded70c72a8eeffdaf33ae91 Mon Sep 17 00:00:00 2001 From: Jens Halm <3116929+jenshalm@users.noreply.github.com> Date: Sat, 20 Aug 2022 19:41:01 +0100 Subject: [PATCH 3/3] adjust build for decoupled blaze versioning --- build.sbt | 2 +- demo/jvm/src/main/scala/laika/webtool/Main.scala | 12 +++++------- project/Dependencies.scala | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/build.sbt b/build.sbt index 93c9522e8..8ebd4826a 100644 --- a/build.sbt +++ b/build.sbt @@ -71,7 +71,7 @@ val munitCE3 = "org.typelevel" %% "munit-cats-effect-3" % versions.mu val fop = "org.apache.xmlgraphics" % "fop" % versions.fop val http4s = Seq( "org.http4s" %% "http4s-dsl" % versions.http4s, - "org.http4s" %% "http4s-blaze-server" % versions.http4s + "org.http4s" %% "http4s-blaze-server" % versions.blaze ) lazy val root = project.in(file(".")) diff --git a/demo/jvm/src/main/scala/laika/webtool/Main.scala b/demo/jvm/src/main/scala/laika/webtool/Main.scala index dd1696ce4..4ad26b669 100644 --- a/demo/jvm/src/main/scala/laika/webtool/Main.scala +++ b/demo/jvm/src/main/scala/laika/webtool/Main.scala @@ -34,11 +34,9 @@ object Main extends IOApp { app.use(_ => IO.never).as(ExitCode.Success) val app: Resource[IO, Server] = - for { - ctx <- Resource.eval(IO.executionContext) - server <- BlazeServerBuilder[IO](ctx) - .bindHttp(8080, "0.0.0.0") - .withHttpApp(service) - .resource - } yield server + BlazeServerBuilder[IO] + .bindHttp(8080, "0.0.0.0") + .withHttpApp(service) + .resource + } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index cb7fbde0b..d7967b972 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,6 +11,7 @@ object Dependencies { val catsEffect = "3.3.5" val fs2 = "3.2.7" val http4s = "0.23.14" + val blaze = "0.23.12" val munit = "0.7.29" val munitCE3 = "1.0.7"