Remote / foldkit-remote-server/fetch

serveFetch

function · packages/remote-server/src/fetch.ts:232

function serveFetch<P, R, Env, RP = never>(
  config: FetchConfig<P, R, Env, RP>,
): (request: Request, env: Env) => Promise<Response>

Answers Remote POSTs with Responses: what a Worker's fetch hands to the route. Each request is one Effect, with layer built once for it: resolvePrincipal first, which refuses with RemoteServer.unauthenticated (a 401, its reason the only words the caller reads); then the body. A body that is not JSON, or not a request, is a 400 that reaches no handler; a handler's failure a 500 with its message; anything else this side breaks, the resolver's defects and the layer included, a 500 that says nothing of it. A live open is answered with the stream instead.

ts
export default {
  fetch: serveFetch({
    server,
    resolvePrincipal: request =>
      Effect.succeed({ actorId: request.headers.get('x-actor') ?? 'anon' }),
    layer: env => databaseLayer(drizzle(env.DB)),
  }),
}