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
This commit is contained in:
35
summercms/src/Main.scala
Normal file
35
summercms/src/Main.scala
Normal file
@@ -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 ()
|
||||||
|
|
||||||
|
}
|
||||||
20
summercms/src/api/HealthRoutes.scala
Normal file
20
summercms/src/api/HealthRoutes.scala
Normal file
@@ -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")
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
14
summercms/src/api/Routes.scala
Normal file
14
summercms/src/api/Routes.scala
Normal file
@@ -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
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user