File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed
Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import org.http4s.server.staticcontent.fileService
1212import org .http4s .Response
1313import 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
Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ import scribe.Scribe
1212import cats .effect .kernel .Resource
1313import org .http4s .server .Router
1414import cats .syntax .all .*
15+ import org .http4s .dsl .io .*
1516
1617import 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
Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments