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

Function middleware

packages/platform/src/HttpApiBuilder.ts:937–958  ·  view source on GitHub ↗
(
  ...args: [
    middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
    options?: {
      readonly withContext?: boolean | undefined
    } | undefined
  ] | [
    api: HttpApi.HttpApi.Any,
    middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
    options?: {
      readonly withContext?: boolean | undefined
    } | undefined
  ]
)

Source from the content-addressed store, hash-verified

935 }
936 ): Layer.Layer<never, EX, Exclude<HttpRouter.HttpRouter.ExcludeProvided<R> | RX, Scope>>
937} = (
938 ...args: [
939 middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
940 options?: {
941 readonly withContext?: boolean | undefined
942 } | undefined
943 ] | [
944 api: HttpApi.HttpApi.Any,
945 middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
946 options?: {
947 readonly withContext?: boolean | undefined
948 } | undefined
949 ]
950): any => {
951 const apiFirst = HttpApi.isHttpApi(args[0])
952 const withContext = apiFirst ? args[2]?.withContext === true : (args as any)[1]?.withContext === true
953 const add = withContext ? middlewareAdd : middlewareAddNoContext
954 const middleware = apiFirst ? args[1] : args[0]
955 return (Effect.isEffect(middleware)
956 ? Layer.scopedDiscard(Effect.flatMap(middleware as any, add))
957 : Layer.scopedDiscard(add(middleware as any))).pipe(Layer.provide(Middleware.layer))
958}
959
960/**
961 * A CORS middleware layer that can be provided to the `HttpApiBuilder.serve` layer.

Callers 2

middlewareAddFunction · 0.70
middlewareCorsFunction · 0.70

Calls 3

addFunction · 0.70
pipeMethod · 0.65
provideMethod · 0.65

Tested by

no test coverage detected