@@ -13,6 +13,14 @@ import cats.effect.kernel.Async
1313import org .http4s .scalatags .*
1414import java .time .ZonedDateTime
1515
16+ /** This is expected to be hidden behind a route with the SPA prefix. It will serve the index.html file from all routes.
17+ *
18+ * @param indexOpts
19+ * @param modules
20+ * @param zdt
21+ * @param logger
22+ * @return
23+ */
1624def buildSpaRoute (indexOpts : Option [IndexHtmlConfig ], modules : Ref [IO , Map [String , String ]], zdt : ZonedDateTime )(
1725 logger : Scribe [IO ]
1826)(using
@@ -23,7 +31,7 @@ def buildSpaRoute(indexOpts: Option[IndexHtmlConfig], modules: Ref[IO, Map[Strin
2331 // Root / spaRoute
2432 StaticHtmlMiddleware (
2533 HttpRoutes .of[IO ] {
26- case req @ GET -> root /: path =>
34+ case req @ GET -> _ =>
2735 vanillaTemplate(false , modules).map: html =>
2836 Response [IO ]().withEntity(html)
2937
@@ -35,7 +43,7 @@ def buildSpaRoute(indexOpts: Option[IndexHtmlConfig], modules: Ref[IO, Map[Strin
3543 case Some (IndexHtmlConfig .StylesOnly (dir)) =>
3644 StaticHtmlMiddleware (
3745 HttpRoutes .of[IO ] {
38- case GET -> root /: spaRoute /: path =>
46+ case GET -> _ =>
3947 vanillaTemplate(true , modules).map: html =>
4048 Response [IO ]().withEntity(html)
4149 },
@@ -46,25 +54,7 @@ def buildSpaRoute(indexOpts: Option[IndexHtmlConfig], modules: Ref[IO, Map[Strin
4654 case Some (IndexHtmlConfig .IndexHtmlPath (dir)) =>
4755 StaticFileMiddleware (
4856 HttpRoutes .of[IO ] {
49- case req @ GET -> spaRoute /: path =>
50- StaticFile
51- .fromPath(dir / " index.html" , Some (req))
52- .getOrElseF(NotFound ())
53- .flatMap {
54- f =>
55- f.body
56- .through(text.utf8.decode)
57- .compile
58- .string
59- .flatMap: body =>
60- for str <- injectModulePreloads(modules, body)
61- yield
62- val bytes = str.getBytes()
63- f.withEntity(bytes)
64- f
65-
66- }
67-
57+ case req @ GET -> _ => serveIndexHtml(dir)
6858 },
6959 dir / " index.html"
7060 )(logger)
0 commit comments