Initial version #1

Merged
Thilawyn merged 25 commits from base-project into master 2025-09-18 01:26:10 +02:00
Showing only changes of commit cd0e9e449a - Show all commits

View File

@@ -14,34 +14,26 @@ export const HttpAppDevelopment = router.pipe(
)
const serveWebappDist = Effect.fnUntraced(function*(file: string) {
const serveWebapp = HttpMiddleware.make(() => Effect.gen(function*() {
const path = yield* Path.Path
const fs = yield* FileSystem.FileSystem
const source = path.join(
yield* path.fromFileUrl(new URL(".", import.meta.resolve("@website/webapp"))),
"dist", file,
)
const exists = yield* fs.stat(source).pipe(
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(
Effect.andThen(stat => stat.type === "File"),
Effect.catchAll(() => Effect.succeed(false)),
)
return exists
? yield* HttpServerResponse.setHeader(
yield* HttpServerResponse.file(source),
return yield* HttpServerResponse.setHeader(
yield* HttpServerResponse.file(path.join(dist, isValid ? req.url : "index.html")),
"Cache-Control",
`public, max-age=${Duration.toSeconds("365 days")}, immutable`
)
: yield* HttpServerResponse.setStatus(HttpServerResponse.empty(), 404)
})
}))
export const HttpAppProduction = router.pipe(
HttpRouter.all("/assets/*", Effect.andThen(
HttpServerRequest.HttpServerRequest,
req => serveWebappDist(req.url),
)),
HttpRouter.all("*", serveWebappDist("index.html")),
serveWebapp,
HttpServer.serve(flow(
HttpMiddleware.logger,
HttpMiddleware.xForwardedHeaders,