MCPcopy Index your code
hub / github.com/Effect-TS/effect / toWebHandler

Function toWebHandler

packages/platform/src/HttpLayerRouter.ts:1114–1174  ·  view source on GitHub ↗
(
  appLayer: Layer.Layer<A, E, R>,
  options?: {
    readonly memoMap?: Layer.MemoMap | undefined
    readonly routerConfig?: Partial<FindMyWay.RouterConfig> | undefined
    readonly disableLogger?: boolean | undefined
    /**
     * Middleware to apply to the HTTP server.
     *
     * NOTE: This middleware is applied to the entire HTTP server chain,
     * including the sending of the response. This means that modifications
     * to the response **WILL NOT** be reflected in the final response sent to the
     * client.
     *
     * Use HttpLayerRouter.middleware to create middleware that can modify the
     * response.
     */
    readonly middleware?: (
      effect: Effect.Effect<
        HttpServerResponse.HttpServerResponse,
        Request.Only<"Error", R> | Request.Only<"GlobalError", R> | HttpServerError.RouteNotFound,
        | Scope.Scope
        | HttpServerRequest.HttpServerRequest
        | Request.Only<"Requires", R>
        | Request.Only<"GlobalRequires", R>
      >
    ) => Effect.Effect<HttpServerResponse.HttpServerResponse, HE, HR>
  }
)

Source from the content-addressed store, hash-verified

1112 * @category Server
1113 */
1114export const toWebHandler = <
1115 A,
1116 E,
1117 R extends
1118 | HttpRouter
1119 | Request<"Requires", any>
1120 | Request<"GlobalRequires", any>
1121 | Request<"Error", any>
1122 | Request<"GlobalError", any>,
1123 HE,
1124 HR = Exclude<Request.Only<"Requires", R> | Request.Only<"GlobalRequires", R>, A>
1125>(
1126 appLayer: Layer.Layer<A, E, R>,
1127 options?: {
1128 readonly memoMap?: Layer.MemoMap | undefined
1129 readonly routerConfig?: Partial<FindMyWay.RouterConfig> | undefined
1130 readonly disableLogger?: boolean | undefined
1131 /**
1132 * Middleware to apply to the HTTP server.
1133 *
1134 * NOTE: This middleware is applied to the entire HTTP server chain,
1135 * including the sending of the response. This means that modifications
1136 * to the response **WILL NOT** be reflected in the final response sent to the
1137 * client.
1138 *
1139 * Use HttpLayerRouter.middleware to create middleware that can modify the
1140 * response.
1141 */
1142 readonly middleware?: (
1143 effect: Effect.Effect<
1144 HttpServerResponse.HttpServerResponse,
1145 Request.Only<"Error", R> | Request.Only<"GlobalError", R> | HttpServerError.RouteNotFound,
1146 | Scope.Scope
1147 | HttpServerRequest.HttpServerRequest
1148 | Request.Only<"Requires", R>
1149 | Request.Only<"GlobalRequires", R>
1150 >
1151 ) => Effect.Effect<HttpServerResponse.HttpServerResponse, HE, HR>
1152 }
1153): {
1154 readonly handler: [HR] extends [never]
1155 ? ((request: globalThis.Request, context?: Context.Context<never> | undefined) => Promise<Response>)
1156 : ((request: globalThis.Request, context: Context.Context<HR>) => Promise<Response>)
1157 readonly dispose: () => Promise<void>
1158} => {
1159 let middleware: any = options?.middleware
1160 if (options?.disableLogger !== true) {
1161 middleware = middleware ? compose(middleware, HttpMiddleware.logger) : HttpMiddleware.logger
1162 }
1163 const RouterLayer: Layer.Layer<HttpRouter | A, E> = Layer.provideMerge(
1164 appLayer,
1165 options?.routerConfig
1166 ? Layer.provide(layer, Layer.succeed(RouterConfig, options.routerConfig))
1167 : layer
1168 ) as any
1169 return HttpApp.toWebHandlerLayerWith(RouterLayer, {
1170 toHandler: (r) => Effect.succeed(Context.get(r.context, HttpRouter).asHttpEffect()),
1171 middleware,

Callers

nothing calls this directly

Calls 3

provideMethod · 0.65
getMethod · 0.65
composeFunction · 0.50

Tested by

no test coverage detected