This commit is contained in:
Julien Valverdé
2025-09-13 02:34:29 +02:00
parent cd0e9e449a
commit d81f42d904

View File

@@ -14,29 +14,27 @@ export const HttpAppDevelopment = router.pipe(
)
const serveWebapp = HttpMiddleware.make(() => Effect.gen(function*() {
const serveProductionWebapp = HttpMiddleware.make(() => Effect.gen(function*() {
const path = yield* Path.Path
const fs = yield* FileSystem.FileSystem
const req = yield* HttpServerRequest.HttpServerRequest
const dist = path.join(yield* path.fromFileUrl(new URL(".", import.meta.resolve("@website/webapp"))), "dist")
const isValid = yield* fs.stat(path.join(dist, req.url)).pipe(
const source = path.join(dist, req.url)
const isValid = yield* fs.stat(source).pipe(
Effect.andThen(stat => stat.type === "File"),
Effect.catchAll(() => Effect.succeed(false)),
)
return yield* HttpServerResponse.setHeader(
yield* HttpServerResponse.file(path.join(dist, isValid ? req.url : "index.html")),
yield* HttpServerResponse.file(isValid ? source : path.join(dist, "index.html")),
"Cache-Control",
`public, max-age=${Duration.toSeconds("365 days")}, immutable`
)
}))
export const HttpAppProduction = router.pipe(
serveWebapp,
HttpServer.serve(flow(
HttpMiddleware.logger,
HttpMiddleware.xForwardedHeaders,
)),
serveProductionWebapp,
HttpServer.serve(HttpMiddleware.xForwardedHeaders),
HttpServer.withLogAddress,
)