Remote / foldkit-remote-server/fetch
pageReader
function · packages/remote-server/src/fetch.ts:398
function pageReader<P, R, Env, RP = never>(
config: PageReaderConfig<P, R, Env, RP>,
): (
request: Request,
env: Env,
) => Layer.Layer<RemoteClient, RemoteUnauthenticated>The reader a page render reads through, in the same process: the request's
RemoteClient, answered by the server's own handlers with no HTTP between
them. Give it serveFetch's config with the resolver a page's request
needs: a page GET is a navigation, which carries no header a script adds
(AuthServer.resolver({ …, requests: 'navigation' })).
The principal is resolved, and layer built, when the reader is provided,
and layer closes when the Effect it was provided to ends, so provide it to
the pre-read itself (Data.satisfy(…).pipe(Effect.provide(reader))). A
refusal fails that Effect with Unauthenticated, as a 401 would. It only
reads: a mutation fails with RemoteMutationError and a live open with
RemoteLiveError, since a navigation can be started from another site.