Skip to content

Commit a10ac96

Browse files
committed
format
1 parent 2baca4a commit a10ac96

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

routes/src/app.route.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.http4s.server.staticcontent.fileService
1212
import org.http4s.Response
1313
import org.http4s.Status
1414

15-
def appRoute[F[_]: Files: MonadThrow](stringPath: String)(using f: Async[F]): HttpRoutes[F] = HttpRoutes.of[F] {
15+
def appRoute[F[_]: Files](stringPath: String)(using f: Async[F]): HttpRoutes[F] = HttpRoutes.of[F] {
1616

1717
case req @ GET -> Root / fName ~ "js" =>
1818
StaticFile

routes/src/buildRoutes.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import scribe.Scribe
1212
import cats.effect.kernel.Resource
1313
import org.http4s.server.Router
1414
import cats.syntax.all.*
15+
import org.http4s.dsl.io.*
1516

1617
import cats.Monad
18+
import org.http4s.StaticFile
1719

1820
/** This is a helper function which would allow you to construct a Router which mimics the behaviour of the "live
1921
* server".
@@ -53,7 +55,7 @@ import cats.Monad
5355
* @param f
5456
* @return
5557
*/
56-
def buildRoutes[F[_]](
58+
def frontendRoutes[F[_]](
5759
clientSpaRoutes: Option[(String, HttpRoutes[F])],
5860
staticAssetRoutes: Option[(HttpRoutes[F])],
5961
appRoutes: Option[HttpRoutes[F]]
@@ -65,4 +67,17 @@ def buildRoutes[F[_]](
6567

6668
appRoutes2.combineK(spaRoutes2).combineK(staticAssetRoutes2)
6769

68-
end buildRoutes
70+
end frontendRoutes
71+
72+
def defaultFrontendRoutes[F[_]](spaPrefix: String = "ui") =
73+
val frontendJs = org.http4s.server.staticcontent.resourceServiceBuilder[IO]("").toRoutes
74+
val serveIndexHtmlBelowSpaPrefix = HttpRoutes.of[IO] {
75+
case req @ GET -> _ =>
76+
StaticFile.fromResource("index.html", req.some).getOrElseF(NotFound())
77+
}
78+
frontendRoutes(
79+
Some("ui", serveIndexHtmlBelowSpaPrefix),
80+
None,
81+
Some(frontendJs)
82+
)
83+
end defaultFrontendRoutes

sjsls/src/routes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def routes[F[_]: Files: MonadThrow](
5757
val staticRoutes = Some(staticAssetRoutes(indexOpts, ref, zdt)(logger))
5858

5959
val routes =
60-
buildRoutes[IO](
60+
frontendRoutes[IO](
6161
clientSpaRoutes = spaRoutes,
6262
staticAssetRoutes = staticRoutes,
6363
appRoutes = Some(linkedAppWithCaching)

0 commit comments

Comments
 (0)