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 path = yield* Path.Path
|
||||||
const fs = yield* FileSystem.FileSystem
|
const fs = yield* FileSystem.FileSystem
|
||||||
const req = yield* HttpServerRequest.HttpServerRequest
|
const req = yield* HttpServerRequest.HttpServerRequest
|
||||||
|
|
||||||
const dist = path.join(yield* path.fromFileUrl(new URL(".", import.meta.resolve("@website/webapp"))), "dist")
|
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.andThen(stat => stat.type === "File"),
|
||||||
Effect.catchAll(() => Effect.succeed(false)),
|
Effect.catchAll(() => Effect.succeed(false)),
|
||||||
)
|
)
|
||||||
|
|
||||||
return yield* HttpServerResponse.setHeader(
|
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",
|
"Cache-Control",
|
||||||
`public, max-age=${Duration.toSeconds("365 days")}, immutable`
|
`public, max-age=${Duration.toSeconds("365 days")}, immutable`
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const HttpAppProduction = router.pipe(
|
export const HttpAppProduction = router.pipe(
|
||||||
serveWebapp,
|
serveProductionWebapp,
|
||||||
HttpServer.serve(flow(
|
HttpServer.serve(HttpMiddleware.xForwardedHeaders),
|
||||||
HttpMiddleware.logger,
|
|
||||||
HttpMiddleware.xForwardedHeaders,
|
|
||||||
)),
|
|
||||||
HttpServer.withLogAddress,
|
HttpServer.withLogAddress,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user