Skip to content
Myr

server.ts

This file

Path

apps/web/src/dev/server.ts

40 lines · 1.4 KiB · TypeScript

Last changed by

Merge build/502-web-dev-backend: the web runs locally over a seeded in-process worldoscabrielbefore adoption4aeb23e

History of this file

Take it

Merge build/502-web-dev-backend: the web runs locally over a seeded in-process worldoscabrielbefore adoption4aeb23e

lines 1–40why, one step back
1/**
2 * The dev world as a fetch handler: `POST /rpc` is an `RpcServer` over3 * `Contracts` with the dev handlers, protocol's `Authenticated` server side4 * over dev tokens (`sessions.ts`) and JSON, as the platform's `/rpc` serves5 * it, over a fresh world the seed has brought to its state. `backend.ts`6 * makes the one an isolate serves; a test makes its own.7 */8import { Contracts } from "@repo/protocol/contracts";9import { Layer } from "effect";10import { HttpRouter } from "effect/http";11import { RpcSerialization, RpcServer } from "effect/rpc";1213import { devHandlers } from "./handlers.ts";14import { seedDev } from "./seed.ts";15import { devSessions } from "./sessions.ts";16import { devWorld } from "./world.ts";1718/** A fresh world, seeded. */19const seededWorld = Layer.effectDiscard(seedDev).pipe(20 Layer.provideMerge(devWorld)21);2223/**24 * The contracts at `/rpc` over a fresh, seeded world. `toWebHandler` builds25 * its layer as soon as it is called, so the world is made and seeded from26 * that moment, and a request that arrives before the seed is done waits for27 * it. `dispose` ends the world.28 */29export const devServer = () =>30 HttpRouter.toWebHandler(31 RpcServer.layerHttp({32 group: Contracts,33 path: "/rpc",34 protocol: "http",35 }).pipe(36 Layer.provide([devHandlers, devSessions, RpcSerialization.layerJson]),37 Layer.provide(seededWorld)38 ),39 { disableLogger: true }40 );