MCPcopy
hub / github.com/Effect-TS/effect / toWebHandlerRuntime

Function toWebHandlerRuntime

packages/platform/src/HttpApp.ts:211–241  ·  view source on GitHub ↗
(runtime: Runtime.Runtime<R>)

Source from the content-addressed store, hash-verified

209 * @category conversions
210 */
211export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
212 const httpRuntime: Types.Mutable<Runtime.Runtime<R>> = Runtime.make(runtime)
213 const run = Runtime.runFork(httpRuntime)
214 return <E>(self: Default<E, R | Scope.Scope>, middleware?: HttpMiddleware | undefined) => {
215 const resolveSymbol = Symbol.for("@effect/platform/HttpApp/resolve")
216 const httpApp = toHandled(self, (request, response) => {
217 response = unsafeEjectStreamScope(response)
218 ;(request as any)[resolveSymbol](
219 ServerResponse.toWeb(response, { withoutBody: request.method === "HEAD", runtime })
220 )
221 return Effect.void
222 }, middleware)
223 return (request: Request, context?: Context.Context<never> | undefined): Promise<Response> =>
224 new Promise((resolve) => {
225 const contextMap = new Map<string, any>(runtime.context.unsafeMap)
226 if (Context.isContext(context)) {
227 for (const [key, value] of context.unsafeMap) {
228 contextMap.set(key, value)
229 }
230 }
231 const httpServerRequest = ServerRequest.fromWeb(request)
232 contextMap.set(ServerRequest.HttpServerRequest.key, httpServerRequest)
233 ;(httpServerRequest as any)[resolveSymbol] = resolve
234 httpRuntime.context = Context.unsafeMake(contextMap)
235 const fiber = run(httpApp as any)
236 request.signal?.addEventListener("abort", () => {
237 fiber.unsafeInterruptAsFork(ServerError.clientAbortFiberId)
238 }, { once: true })
239 })
240 }
241}
242
243/**
244 * @since 1.0.0

Callers 2

HttpApp.tsFile · 0.85
handlerFunction · 0.85

Calls 7

toHandledFunction · 0.85
unsafeEjectStreamScopeFunction · 0.85
addEventListenerMethod · 0.80
runFunction · 0.70
makeMethod · 0.65
setMethod · 0.65
unsafeInterruptAsForkMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…