(runtime: Runtime.Runtime<R>)
| 209 | * @category conversions |
| 210 | */ |
| 211 | export 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 |
no test coverage detected
searching dependent graphs…