( context: Context.Context<Provided> )
| 230 | * @since 4.0.0 |
| 231 | */ |
| 232 | export const toWebHandlerWith = <Provided, R = never, ReqR = Exclude<R, Provided | Scope.Scope | HttpServerRequest>>( |
| 233 | context: Context.Context<Provided> |
| 234 | ) => |
| 235 | <E>( |
| 236 | self: Effect.Effect<HttpServerResponse, E, R>, |
| 237 | middleware?: HttpMiddleware | undefined |
| 238 | ): [ReqR] extends [never] ? |
| 239 | (request: Request, context?: Context.Context<never> | undefined) => Promise<globalThis.Response> |
| 240 | : (request: Request, context: Context.Context<ReqR>) => Promise<globalThis.Response> => |
| 241 | { |
| 242 | const resolveSymbol = Symbol.for("@effect/platform/HttpApp/resolve") |
| 243 | const httpApp = toHandled(self, (request, response) => { |
| 244 | response = scopeTransferToStream(response) |
| 245 | ;(request as any)[resolveSymbol]( |
| 246 | Response.toWeb(response, { withoutBody: request.method === "HEAD", context }) |
| 247 | ) |
| 248 | return Effect.void |
| 249 | }, middleware) |
| 250 | return (request: Request, _context?: Context.Context<never> | undefined): Promise<globalThis.Response> => |
| 251 | new Promise((resolve) => { |
| 252 | let reqContext = context |
| 253 | if (Context.isContext(_context)) { |
| 254 | for (const [key, value] of _context.mapUnsafe) { |
| 255 | reqContext = Context.addUnsafe(reqContext, key, value) |
| 256 | } |
| 257 | } |
| 258 | const httpServerRequest = Request.fromWeb(request) |
| 259 | reqContext = Context.add(reqContext, HttpServerRequest, httpServerRequest) |
| 260 | ;(httpServerRequest as any)[resolveSymbol] = resolve |
| 261 | const fiber = Effect.runForkWith(reqContext)(httpApp as any) |
| 262 | request.signal?.addEventListener("abort", () => { |
| 263 | fiber.interruptUnsafe(undefined, ClientAbort.annotation) |
| 264 | }, { once: true }) |
| 265 | }) |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Converts an HTTP server effect into a Web `Request` handler using an empty base context. |
no test coverage detected