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(
134
134
" -w" ,
135
135
s " $moduleName.fastLinkJS "
136
136
) ++ 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
138
146
139
147
for
140
148
_ <- logger.trace(" Starting buildRunnerMill" ).toResource
Original file line number Diff line number Diff line change @@ -162,13 +162,12 @@ def routes[F[_]: Files: MonadThrow](
162
162
clientRoutingPrefix match
163
163
case None => HttpRoutes .empty[IO ]
164
164
case Some (spaRoute) =>
165
- indexOpts match
165
+ val r = indexOpts match
166
166
case None =>
167
167
Root / spaRoute
168
168
StaticHtmlMiddleware (
169
169
HttpRoutes .of[IO ] {
170
- case GET -> root /: spaRoute /: path =>
171
- // logger.trace(path) >>
170
+ case req @ GET -> root /: path =>
172
171
IO (
173
172
Response [IO ]().withEntity(vanillaTemplate(false ))
174
173
)
@@ -196,6 +195,8 @@ def routes[F[_]: Files: MonadThrow](
196
195
dir / " index.html"
197
196
)(logger)
198
197
198
+ Router (s " / $spaRoute" -> r)
199
+
199
200
val refreshRoutes = HttpRoutes .of[IO ] {
200
201
case GET -> Root / " api" / " v1" / " sse" =>
201
202
val keepAlive = fs2.Stream .fixedRate[IO ](10 .seconds).as(KeepAlive ())
@@ -208,9 +209,9 @@ def routes[F[_]: Files: MonadThrow](
208
209
val app = logMiddler(
209
210
refreshRoutes
210
211
.combineK(linkedAppWithCaching)
211
- .combineK(proxyRoutes)
212
212
.combineK(clientSpaRoutes)
213
213
.combineK(staticAssetRoutes)
214
+ .combineK(proxyRoutes)
214
215
)
215
216
216
217
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:
210
210
}
211
211
212
212
val requestHtml = Request [IO ](uri = uri " / " )
213
- val etag = " 699892091"
213
+ // val etag = "699892091"
214
214
215
215
val checkRespHtml = client
216
216
.run(requestHtml)
Original file line number Diff line number Diff line change @@ -196,6 +196,60 @@ trait PlaywrightTest extends munit.FunSuite:
196
196
assertEquals(outFail.statusCode, 404 )
197
197
}
198
198
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
+
199
253
files.test(" no styles" ) {
200
254
testDir =>
201
255
val thisTestPort = basePort + 4
You can’t perform that action at this time.
0 commit comments