From 3757cf883ba4a78b74b00d0d1f355d53dec56104 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Wed, 4 Feb 2026 21:43:24 +0100 Subject: [PATCH] feat(01-01): create HTTP routes and Main entry point - HealthRoutes with GET /health returning 'ok' - Routes composition point for all route modules - Main extends ZIOAppDefault with HOCON config - ASCII sun banner with SUMMERCMS branding - Server reads port from application.conf --- summercms/src/Main.scala | 35 ++++++++++++++++++++++++++++ summercms/src/api/HealthRoutes.scala | 20 ++++++++++++++++ summercms/src/api/Routes.scala | 14 +++++++++++ 3 files changed, 69 insertions(+) create mode 100644 summercms/src/Main.scala create mode 100644 summercms/src/api/HealthRoutes.scala create mode 100644 summercms/src/api/Routes.scala diff --git a/summercms/src/Main.scala b/summercms/src/Main.scala new file mode 100644 index 0000000..5006997 --- /dev/null +++ b/summercms/src/Main.scala @@ -0,0 +1,35 @@ +import zio.* +import zio.http.* +import zio.config.typesafe.TypesafeConfigProvider + +import api.Routes +import _root_.config.{AppConfig as SummerConfig} + +object Main extends ZIOAppDefault { + + private val banner: String = + """ + | . + | \ | / + | '-.ooooo.-' + | --- ooooo --- + | .-'ooooo'-. + | / | \ + | ' + | + | S U M M E R C M S + |""".stripMargin + + override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = + Runtime.setConfigProvider(TypesafeConfigProvider.fromResourcePath()) + + override def run: ZIO[Any, Any, Any] = + for { + cfg <- ZIO.config[SummerConfig](SummerConfig.config) + _ <- Console.printLine(banner) + _ <- Console.printLine(s" Starting on port ${cfg.server.port}...") + _ <- Console.printLine("") + _ <- Server.serve(Routes.routes).provide(Server.defaultWithPort(cfg.server.port)) + } yield () + +} diff --git a/summercms/src/api/HealthRoutes.scala b/summercms/src/api/HealthRoutes.scala new file mode 100644 index 0000000..85f8beb --- /dev/null +++ b/summercms/src/api/HealthRoutes.scala @@ -0,0 +1,20 @@ +package api + +import zio.http.* + +/** Health check endpoints + * + * Provides basic health check endpoint for load balancers and monitoring systems. The /health + * endpoint returns 200 OK when the server is running. + * + * Future endpoints: + * - /ready will verify database connectivity + */ +object HealthRoutes { + + val routes: Routes[Any, Response] = + Routes( + Method.GET / "health" -> Handler.text("ok") + ) + +} diff --git a/summercms/src/api/Routes.scala b/summercms/src/api/Routes.scala new file mode 100644 index 0000000..4c232ae --- /dev/null +++ b/summercms/src/api/Routes.scala @@ -0,0 +1,14 @@ +package api + +import zio.http.* + +/** Route composition point + * + * Aggregates all route modules in the application. Add new route modules here as they're created. + */ +object Routes { + + val routes: Routes[Any, Response] = + HealthRoutes.routes + +}