Skip to content

Commit

Permalink
Run separate HTTPS server when SSL enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Feb 16, 2024
1 parent 576323d commit f0efd0a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentRegist
import com.snowplowanalytics.snowplow.enrich.common.enrichments.registry.{Enrichment, EnrichmentConf}
import com.snowplowanalytics.snowplow.enrich.common.utils.{HttpClient, ShiftExecution}
import com.snowplowanalytics.snowplow.micro.Configuration.MicroConfig
import org.http4s.HttpRoutes
import org.http4s.ember.client.EmberClientBuilder
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
Expand Down Expand Up @@ -74,12 +75,13 @@ object Run {
allRoutes = miniRoutes <+> collectorRoutes
_ <- HttpServer.build[IO](
allRoutes,
if (config.collector.ssl.enable) config.collector.ssl.port else config.collector.port,
config.collector.ssl.enable,
config.collector.port,
secure = false,
config.collector.hsts,
config.collector.networking,
config.collector.monitoring.metrics
)
_ <- runHttpsServerIfEnabled(config, allRoutes)
} yield ()
}

Expand Down Expand Up @@ -135,7 +137,22 @@ object Run {
logger.info(s"Downloading $uri...") *> IO(uri.toURL #> new File(location) !!)
}
}


private def runHttpsServerIfEnabled(config: MicroConfig, routes: HttpRoutes[IO]): Resource[IO, Unit] = {
if (config.collector.ssl.enable) {
HttpServer.build[IO](
routes,
config.collector.ssl.port,
secure = true,
config.collector.hsts,
config.collector.networking,
config.collector.monitoring.metrics
).void
} else {
Resource.unit
}
}

private def handleAppErrors(appOutput: EitherT[IO, String, ExitCode]): IO[ExitCode] = {
appOutput
.leftSemiflatMap { error =>
Expand Down

0 comments on commit f0efd0a

Please sign in to comment.