Initial version #1
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user