Optimizations for the Website service (#9)

This PR contains the work done to provide optimizations to the current service, such as a health-check endpoint, pre-renders static HTML pages, and hardens the error page's CSP.

To provide further details about the work:

* Added the `HealthController` controller serving GET `/health` with a static JSON payload.
* Added the `CachedHTMLResponse` response, which renders a static HTMLDocument to bytes once and reuses them per request (no Content-Length, so responses stay compressible).
* Integrated the response into the `RootController` and the  `NotFoundMiddleware` middleware to avoid re-rendering on hot paths.
* Added a `RouterMethods.addRoutes(_:)` extension and switched the router in App+build to use it.
* Moved the inline style from the `ErrorPage` page into a dedicated style file so the CSP needs no inline-style escape hatch.
* Fixed the `IndexPage` page path inconsistencies.
* Written the `README` file.

Reviewed-on: rock-n-code/loud-amsterdam#9
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 14:18:04 +00:00
committed by javier
parent 6b6389cb0f
commit 847058d642
16 changed files with 508 additions and 95 deletions
+6 -2
View File
@@ -155,7 +155,8 @@ private func logger(
/// responses larger than `minimumResponseSizeToCompress` when the client advertises support, the
/// not-found middleware that serves the error page, and the static file middleware that serves the
/// contents of `staticFilesPath` (tagging responses with the given `cacheControl` directives), then
/// adds the `RootController` routes that render the landing page.
/// adds the `RootController` routes that render the landing page and the `HealthController` routes
/// that serve the health check.
///
/// The security-headers middleware sits just inside request logging so it covers every response that
/// reaches a client the landing page, the compressed responses, the rendered error page, and the
@@ -191,7 +192,10 @@ private func router(
)
}
router.addRoutes(RootController<AppRequestContext>().routes)
router.addRoutes {
RootController<AppRequestContext>().routes
HealthController<AppRequestContext>().routes
}
return router
}