| 244 | * synthetic platform. |
| 245 | */ |
| 246 | export const toApiHandler = ( |
| 247 | // The app layer must already provide every route requirement; only the HTTP |
| 248 | // platform is missing, which `HttpServer.layerServices` supplies below. Typed |
| 249 | // loosely (success/error/requirement channels erased) because each host's app |
| 250 | // layer has a different, fully-resolved set — self-host's `AppLayer` outputs |
| 251 | // `never`, local's outputs `ExecutorService | …` (provideMerge keeps them in |
| 252 | // the success channel). The runtime contract is the same either way. |
| 253 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 254 | appLayer: Layer.Layer<any, any, any>, |
| 255 | ): ApiHandler => { |
| 256 | // `HttpServer.layerServices` supplies the synthetic HTTP platform so |
| 257 | // `toWebHandler` can run handlers without a listening socket. |
| 258 | const web = HttpRouter.toWebHandler(appLayer.pipe(Layer.provideMerge(HttpServer.layerServices))); |
| 259 | // With every requirement provided the leftover `HR` is `never`, so `handler` |
| 260 | // is the one-arg `(request) => Promise<Response>` form — but the loose |
| 261 | // `R = any` input widens `HR` to `any` (a two-arg signature), so narrow back |
| 262 | // to the runtime contract. |
| 263 | const handler = web.handler as (request: Request) => Promise<Response>; |
| 264 | return { handler, dispose: web.dispose }; |
| 265 | }; |