HTML rendering support for the Website service (#5)

This PR contains the work done to replace the use of static _HTML_ files with type-safe HTML rendered server-side via **Elementary** through **Hummingbird**.

To provide further details about the work done:

* Added the **Elementary** dependencies.
* Added the `IndexPage` and `ErrorPage` pages, ported from the old HTML boilerplate; removed the static files.
* Added the `RootController` controller serving GET / using the `IndexPage` page, wired into the router.
* Reworked the `NotFoundMiddleware` middleare to render `ErrorPage` page directly; non-notFound errors still propagate.
* the `FileMiddleware` middleware no longer searches for any static `index.html` file.
* Simplified the `StaticFile` enumeration, dropped unused constants and now-unnecessary throws.

Reviewed-on: rock-n-code/loud-amsterdam#5
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
2026-06-28 05:07:19 +00:00
committed by javier
parent f5f14eb97c
commit a621ada0bf
17 changed files with 460 additions and 244 deletions
+8 -10
View File
@@ -9,10 +9,9 @@ import WebsiteCore
/// then assembles the router, server configuration, and logger.
/// - Parameter reader: the configuration reader the values are read from.
/// - Returns: the configured application, ready to run as a service.
/// - Throws: an error if the router fails to build.
func application(
reader: ConfigReader
) async throws -> some ApplicationProtocol {
) async -> some ApplicationProtocol {
let logLevel = reader.string(
forKey: .Log.level,
as: Logger.Level.self,
@@ -65,9 +64,9 @@ private func logger(
/// Builds the application's router.
///
/// Registers, in order, the request-logging middleware, the not-found middleware that serves
/// the error page, and the static file middleware that serves the contents of `staticFilesPath`
/// (falling back to `index.html` for directory requests).
/// Registers the request-logging middleware, the not-found middleware that serves the error
/// page, and the static file middleware that serves the contents of `staticFilesPath`, then
/// adds the `RootController` routes that render the landing page.
/// - Parameters:
/// - staticFilesPath: the folder, relative to the working directory, the static files are served from.
/// - logLevel: the level the request-logging middleware logs at.
@@ -80,12 +79,11 @@ private func router(
router.addMiddleware {
LogRequestsMiddleware(logLevel)
NotFoundMiddleware(staticFilesPath)
FileMiddleware(
staticFilesPath,
searchForIndexHtml: true
)
NotFoundMiddleware()
FileMiddleware(staticFilesPath)
}
router.addRoutes(RootController<AppRequestContext>().routes)
return router
}