Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preview server: revert back to blaze backend for better user experience #311

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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.blaze
)

lazy val root = project.in(file("."))
Expand Down
11 changes: 5 additions & 6 deletions demo/jvm/src/main/scala/laika/webtool/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,9 +34,9 @@ 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")
BlazeServerBuilder[IO]
.bindHttp(8080, "0.0.0.0")
.withHttpApp(service)
.build
.resource

}
26 changes: 12 additions & 14 deletions preview/src/main/scala/laika/preview/ServerBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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._

Expand Down Expand Up @@ -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) ++
Expand Down Expand Up @@ -133,17 +131,17 @@ 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,
val includePDF: Boolean,
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,
Expand All @@ -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).
*/
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ 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 blaze = "0.23.12"

val munit = "0.7.29"
val munitCE3 = "1.0.7"
Expand Down
13 changes: 6 additions & 7 deletions sbt/src/main/scala/laika/sbt/LaikaPreviewConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package laika.sbt

import com.comcast.ip4s._
import laika.preview.ServerConfig

import scala.concurrent.duration.FiniteDuration
Expand All @@ -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).
*/
Expand Down