MCPcopy Create free account
hub / github.com/Effect-TS/effect / middleware

Function middleware

packages/platform/src/HttpApiBuilder.ts:948–969  ·  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

946 }
947 ): Layer.Layer<never, EX, Exclude<HttpRouter.HttpRouter.ExcludeProvided<R> | RX, Scope>>
948} = (
949 ...args: [
950 middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
951 options?: {
952 readonly withContext?: boolean | undefined
953 } | undefined
954 ] | [
955 api: HttpApi.HttpApi.Any,
956 middleware: MiddlewareFn<any, any> | Effect.Effect<MiddlewareFn<any, any>, any, any>,
957 options?: {
958 readonly withContext?: boolean | undefined
959 } | undefined
960 ]
961): any => {
962 const apiFirst = HttpApi.isHttpApi(args[0])
963 const withContext = apiFirst ? args[2]?.withContext === true : (args as any)[1]?.withContext === true
964 const add = withContext ? middlewareAdd : middlewareAddNoContext
965 const middleware = apiFirst ? args[1] : args[0]
966 return (Effect.isEffect(middleware)
967 ? Layer.scopedDiscard(Effect.flatMap(middleware as any, add))
968 : Layer.scopedDiscard(add(middleware as any))).pipe(Layer.provide(Middleware.layer))
969}
970
971/**
972 * 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