Static serve

This commit is contained in:
Julien Valverdé
2025-09-12 16:46:23 +02:00
parent f8c35eba1a
commit 5dba4eff03
3 changed files with 15 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { HttpMiddleware, HttpRouter, HttpServer, HttpServerResponse, Path } from "@effect/platform"
import { Effect, flow, Layer } from "effect"
import { Console, Effect, flow, Layer } from "effect"
const router = HttpRouter.empty.pipe(
@@ -13,15 +13,21 @@ export const HttpAppDevelopment = router.pipe(
HttpServer.withLogAddress,
)
export const HttpAppProduction = Effect.all([
Path.Path,
Effect.succeed(import.meta.resolve("@website/webapp")),
]).pipe(
Effect.map(([path, webappDist]) => router.pipe(
export const HttpAppProduction = Effect.Do.pipe(
Effect.bind("path", () => Path.Path),
Effect.bind("webappDist", ({ path }) => Effect.map(
path.fromFileUrl(new URL(".", import.meta.resolve("@website/webapp"))),
v => path.join(v, "dist"),
)),
Effect.map(({ path, webappDist }) => router.pipe(
HttpRouter.all("/", HttpServerResponse.file(path.join(webappDist, "index.html"))),
HttpRouter.all("/assets", HttpServerResponse.file(path.join(webappDist, "assets"))),
HttpServer.serve(HttpMiddleware.xForwardedHeaders),
HttpServer.serve(flow(
HttpMiddleware.logger,
HttpMiddleware.xForwardedHeaders,
)),
HttpServer.withLogAddress,
)),

View File

@@ -2,7 +2,7 @@
"name": "@website/webapp",
"private": true,
"type": "module",
"module": "./dist",
"module": "./stub.ts",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",

1
packages/webapp/stub.ts Normal file
View File

@@ -0,0 +1 @@
export {}