From a2fda0768b9809d1e1723d30e327c99e5685b643 Mon Sep 17 00:00:00 2001 From: jczuchnowski Date: Fri, 28 Apr 2023 00:42:27 +0200 Subject: [PATCH] Refactor configuration and server startup --- src/main/g8/src/main/resources/application.conf | 7 ++++--- src/main/g8/src/main/scala/$package$/Boot.scala | 8 ++++---- .../main/scala/$package$/config/Configuration.scala | 11 +++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/g8/src/main/resources/application.conf b/src/main/g8/src/main/resources/application.conf index 2c16a69..b840d80 100644 --- a/src/main/g8/src/main/resources/application.conf +++ b/src/main/g8/src/main/resources/application.conf @@ -1,12 +1,13 @@ api { - port = "8080" + host = "0.0.0.0" + port = 8080 } db { dataSource { user=postgres - databaseName=quickstart-db - password=postgres + databaseName=items + password=12345 portNumber=5432 serverName=127.0.0.1 } diff --git a/src/main/g8/src/main/scala/$package$/Boot.scala b/src/main/g8/src/main/scala/$package$/Boot.scala index 29cde35..2eabc64 100644 --- a/src/main/g8/src/main/scala/$package$/Boot.scala +++ b/src/main/g8/src/main/scala/$package$/Boot.scala @@ -2,7 +2,7 @@ package $package$ import $package$.api._ import $package$.api.healthcheck._ -import $package$.config.Configuration._ +import $package$.config.Configuration.ApiConfig import $package$.infrastructure._ import io.getquill.jdbczio.Quill import io.getquill.Literal @@ -25,9 +25,9 @@ object Boot extends ZIOAppDefault: private val serverLayer = ZLayer - .service[ServerConfig] + .service[ApiConfig] .flatMap { cfg => - Server.defaultWithPort(cfg.get.port) + Server.defaultWith(_.binding(cfg.get.host, cfg.get.port)) } .orDie @@ -39,7 +39,7 @@ object Boot extends ZIOAppDefault: program.provide( healthCheckServiceLayer, serverLayer, - ServerConfig.layer, + ApiConfig.layer, repoLayer, postgresLayer, dataSourceLayer, diff --git a/src/main/g8/src/main/scala/$package$/config/Configuration.scala b/src/main/g8/src/main/scala/$package$/config/Configuration.scala index 4f57db9..7d9afd1 100644 --- a/src/main/g8/src/main/scala/$package$/config/Configuration.scala +++ b/src/main/g8/src/main/scala/$package$/config/Configuration.scala @@ -1,23 +1,22 @@ package $package$.config -import $package$.config.Configuration.ServerConfig import com.typesafe.config.ConfigFactory import zio._ import zio.config._ import zio.config.ConfigDescriptor._ -import zio.config.ConfigSource._ import zio.config.typesafe.TypesafeConfigSource object Configuration: - final case class ServerConfig(port: Int) + final case class ApiConfig(host: String, port: Int) - object ServerConfig: + object ApiConfig: private val serverConfigDescription = nested("api") { - int("port").default(8090) - }.to[ServerConfig] + string("host") <*> + int("port") + }.to[ApiConfig] val layer = ZLayer( read(