Skip to content

Commit 6027e87

Browse files
committed
.
1 parent 366bb78 commit 6027e87

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ test:
1414
checkOpts:
1515
mill project.run --help
1616

17+
1718
jvmServe:
1819
mill -w project.runBackground --build-tool scala-cli --project-dir /Users/simon/Code/indigoLite --log-level info --browse-on-open-at / --path-to-index-html /Users/simon/Code/indigoLite/static
1920

21+
proxy:
22+
mill -w project.runBackground --project-dir /Users/simon/Code/viteless --port 3006 --proxy-prefix-path /api --proxy-target-port 8080 --log-level trace
23+
24+
2025
goViteless:
2126
mill -w project.run --project-dir /Users/simon/Code/viteless --styles-dir /Users/simon/Code/viteless/styles
2227

project/src/build.runner.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,16 @@ def buildRunnerMill(
127127
.background
128128
.void
129129

130+
val millargs = List(
131+
"-w",
132+
s"$moduleName.fastLinkJS",
133+
"-j",
134+
"0"
135+
) ++ extraBuildArgs
130136
// TODO pipe this to stdout so that we can see linker progress / errors.
131137
val builder = ProcessBuilder(
132138
"mill",
133-
List(
134-
"-w",
135-
s"$moduleName.fastLinkJS"
136-
) ++ extraBuildArgs
139+
millargs
137140
).withWorkingDirectory(workDir)
138141
.spawn[IO]
139142
.use {
@@ -147,6 +150,7 @@ def buildRunnerMill(
147150
for
148151
_ <- logger.trace("Starting buildRunnerMill").toResource
149152
_ <- logger.trace(s"watching path $watchLinkComplePath").toResource
153+
_ <- logger.trace(s"running mill with args $millargs").toResource
150154
_ <- builder
151155
_ <- watcher
152156
yield ()

project/src/middleware/ETagMiddleware.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ object ETagMiddleware:
6363
OptionT.liftF(logger.debug("No ETag header in query, service it")) >>
6464
service(req).semiflatMap {
6565
resp =>
66-
respondWithEtag(resp)
66+
logger.trace(resp.toString) >>
67+
respondWithEtag(resp)
6768
}
6869
end match
6970
}

project/src/proxy.http.scala

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ object HttpProxy:
2929

3030
val routes: HttpRoutes[F] = HttpRoutes.of {
3131
case (req: Request[F]) =>
32-
println(req)
32+
// println("in proxy")
33+
// println(req)
3334
val pathRendered = pathPrefix + req.uri.path.renderString
35+
// println(pathRendered)
3436
val host = req.headers.get[Host].map(_.host).getOrElse("") // Host set otherwise empty string
3537
val newServers = servers.filter(_.serverNames.contains(host))
36-
38+
// println(host)
39+
// println(newServers)
3740
val exact =
3841
newServers
3942
.flatMap(_.locations)
@@ -60,12 +63,13 @@ object HttpProxy:
6063
.headOption
6164
.map(_._2)
6265
}
63-
6466
proxy.fold(
6567
Response[F](Status.NotFound).withEntity("No Route Found").pure[F]
6668
)(
67-
proxyThrough[F](_, upstreams)
68-
.flatMap(uri => client.toHttpApp(req.removeHeader[Host].withUri(uri.addPath(pathRendered))))
69+
proxyThrough[F](_, upstreams).flatMap {
70+
uri =>
71+
client.toHttpApp(req.removeHeader[Host].withUri(uri.addPath(pathRendered)))
72+
}
6973
)
7074
}
7175

@@ -77,6 +81,8 @@ object HttpProxy:
7781
proxyPass: String,
7882
upstreams: Map[String, NonEmptyList[ProxyConfig.UpstreamServer]]
7983
): F[Uri] =
84+
println(s"proxypass $proxyPass")
85+
println(upstreams)
8086
if !proxyPass.contains("$") then Uri.fromString(proxyPass).liftTo[F]
8187
else
8288
extractVariable(proxyPass).flatMap {
@@ -90,6 +96,8 @@ object HttpProxy:
9096
)
9197
)
9298
}
99+
end if
100+
end proxyThrough
93101

94102
private def extractVariable[F[_]: ApplicativeThrow](s: String): F[(String, String, String)] =
95103
s.split('$').toList match
@@ -132,6 +140,8 @@ object HttpProxy:
132140

133141
def xForwardedMiddleware[G[_], F[_]](http: Http[G, F]): Http[G, F] = Kleisli {
134142
(req: Request[F]) =>
143+
println("in middleware")
144+
println(req)
135145
req
136146
.remote
137147
.fold(http.run(req)) {

project/src/proxy.routes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def proxyConf(proxyTarget: Option[Port], pathPrefix: Option[String]): Resource[I
5757
locations = List(
5858
ProxyConfig.Location(
5959
matcher = LocationMatcher.Prefix(prfx),
60-
proxyPass = "http://$$backend"
60+
proxyPass = "http://$backend"
6161
)
6262
)
6363
),

project/src/routes.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def routes[F[_]: Files: MonadThrow](
6060
StaticFile
6161
.fromPath(fs2.io.file.Path(stringPath) / req.uri.path.renderString, Some(req))
6262
.getOrElseF(NotFound())
63+
64+
case req @ GET -> Root / fName ~ "map" =>
65+
StaticFile
66+
.fromPath(fs2.io.file.Path(stringPath) / req.uri.path.renderString, Some(req))
67+
.getOrElseF(NotFound())
68+
6369
},
6470
ref
6571
)(logger)

0 commit comments

Comments
 (0)