Skip to content
Myr

client.ts

This file

Path

apps/web/src/server/client.ts

41 lines · 1.2 KiB · TypeScript

Last changed by

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–41why, one step back
1import { Client, Contracts } from "@repo/protocol/contracts";
2import { Layer } from "effect";3import { FetchHttpClient } from "effect/http";4import { RpcClient, RpcSerialization } from "effect/rpc";56import { backend } from "#backend";78import type { Backend } from "./rpc.ts";910const inProcess =11 (over: Backend, env: Env, caller: Request | undefined): typeof fetch =>12 (input, init) => {13 const request = new Request(input, init);14 const cookie = caller?.headers.get("cookie");1516 if (cookie !== null && cookie !== undefined) {17 request.headers.set("cookie", cookie);18 }1920 return over(request, env);21 };2223export const serverClientOver =24 (over: Backend) =>25 (env: Env, request?: Request): Layer.Layer<Client> =>26 Layer.effect(Client)(RpcClient.make(Contracts)).pipe(27 Layer.provide(28 RpcClient.layerProtocolHttp({29 url: new URL("/rpc", request?.url ?? env.PUBLIC_PLATFORM_URL).href,30 })31 ),32 Layer.provide([FetchHttpClient.layer, RpcSerialization.layerJson]),33 Layer.provide(34 Layer.succeed(FetchHttpClient.Fetch)(inProcess(over, env, request))35 )36 );3738export const serverClient: (39 env: Env,40 request?: Request41) => Layer.Layer<Client> = serverClientOver(backend);