File tree Expand file tree Collapse file tree 4 files changed +69
-6
lines changed
Expand file tree Collapse file tree 4 files changed +69
-6
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,15 @@ def buildRunnerMill(
134134 " -w" ,
135135 s " $moduleName.fastLinkJS "
136136 ) ++ extraBuildArgs
137- ).withWorkingDirectory(workDir).spawn[IO ].useForever.map(_ => ()).background.void
137+ ).withWorkingDirectory(workDir)
138+ .spawn[IO ]
139+ .use {
140+ p =>
141+ // p.stderr.through(fs2.io.stdout).compile.drain >>
142+ p.stdout.through(text.utf8.decode).debug().compile.drain
143+ }
144+ .background
145+ .void
138146
139147 for
140148 _ <- logger.trace(" Starting buildRunnerMill" ).toResource
Original file line number Diff line number Diff line change @@ -162,13 +162,12 @@ def routes[F[_]: Files: MonadThrow](
162162 clientRoutingPrefix match
163163 case None => HttpRoutes .empty[IO ]
164164 case Some (spaRoute) =>
165- indexOpts match
165+ val r = indexOpts match
166166 case None =>
167167 Root / spaRoute
168168 StaticHtmlMiddleware (
169169 HttpRoutes .of[IO ] {
170- case GET -> root /: spaRoute /: path =>
171- // logger.trace(path) >>
170+ case req @ GET -> root /: path =>
172171 IO (
173172 Response [IO ]().withEntity(vanillaTemplate(false ))
174173 )
@@ -196,6 +195,8 @@ def routes[F[_]: Files: MonadThrow](
196195 dir / " index.html"
197196 )(logger)
198197
198+ Router (s " / $spaRoute" -> r)
199+
199200 val refreshRoutes = HttpRoutes .of[IO ] {
200201 case GET -> Root / " api" / " v1" / " sse" =>
201202 val keepAlive = fs2.Stream .fixedRate[IO ](10 .seconds).as(KeepAlive ())
@@ -208,9 +209,9 @@ def routes[F[_]: Files: MonadThrow](
208209 val app = logMiddler(
209210 refreshRoutes
210211 .combineK(linkedAppWithCaching)
211- .combineK(proxyRoutes)
212212 .combineK(clientSpaRoutes)
213213 .combineK(staticAssetRoutes)
214+ .combineK(proxyRoutes)
214215 )
215216
216217 clientRoutingPrefix.fold(IO .unit)(s => logger.trace(s " client spa at : $s" )).toResource >>
Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ class RoutesSuite extends CatsEffectSuite:
210210 }
211211
212212 val requestHtml = Request [IO ](uri = uri " / " )
213- val etag = " 699892091"
213+ // val etag = "699892091"
214214
215215 val checkRespHtml = client
216216 .run(requestHtml)
Original file line number Diff line number Diff line change @@ -196,6 +196,60 @@ trait PlaywrightTest extends munit.FunSuite:
196196 assertEquals(outFail.statusCode, 404 )
197197 }
198198
199+ files.test(" proxy server and SPA client apps" ) {
200+ testDir =>
201+ val backendPort = 8090
202+ val thisTestPort = basePort + 3
203+ // use http4s to instantiate a simple server that responds to /api/hello with 200, use Http4sEmberServer
204+ EmberServerBuilder
205+ .default[IO ]
206+ .withHttpApp(
207+ HttpRoutes
208+ .of[IO ] {
209+ case GET -> Root / " api" / " hello" =>
210+ Ok (" hello world" )
211+ }
212+ .orNotFound
213+ )
214+ .withPort(Port .fromInt(backendPort).get)
215+ .build
216+ .allocated
217+ .unsafeToFuture()
218+
219+ LiveServer
220+ .run(
221+ List (
222+ " --build-tool" ,
223+ " scala-cli" ,
224+ " --project-dir" ,
225+ testDir.toString,
226+ " --styles-dir" ,
227+ styleDir(testDir).toString,
228+ " --client-routes-prefix" ,
229+ " /app" ,
230+ " --port" ,
231+ thisTestPort.toString,
232+ " --proxy-target-port" ,
233+ backendPort.toString,
234+ " --proxy-prefix-path" ,
235+ " /api"
236+ )
237+ )
238+ .unsafeToFuture()
239+
240+ Thread .sleep(1000 ) // give the thing time to start.
241+
242+ val out = requests.get(s " http://localhost: $thisTestPort/api/hello " , check = false )
243+ assertEquals(out.statusCode, 200 )
244+ assertEquals(out.text(), " hello world" )
245+
246+ val outFail = requests.get(s " http://localhost: $thisTestPort/api/nope " , check = false )
247+ assertEquals(outFail.statusCode, 404 )
248+
249+ val canGetHtml = requests.get(s " http://localhost: $thisTestPort" , check = false )
250+ assertEquals(canGetHtml.statusCode, 200 )
251+ }
252+
199253 files.test(" no styles" ) {
200254 testDir =>
201255 val thisTestPort = basePort + 4
You can’t perform that action at this time.
0 commit comments