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

Function applyMiddleware

packages/effect/src/unstable/httpapi/HttpApiBuilder.ts:850–866  ·  view source on GitHub ↗
(
  group: Group,
  endpoint: HttpApiEndpoint.Top,
  context: Context.Context<any>,
  handler: A
)

Source from the content-addressed store, hash-verified

848}
849
850const applyMiddleware = <Group extends HttpApiGroup.Constraint, A extends Effect.Effect<any, any, any>>(
851 group: Group,
852 endpoint: HttpApiEndpoint.Top,
853 context: Context.Context<any>,
854 handler: A
855) => {
856 const options = { group, endpoint }
857 for (const key_ of endpoint.middlewares) {
858 const key = key_ as HttpApiMiddleware.AnyService
859 const service = Context.getUnsafe(context, key)
860 const apply = HttpApiMiddleware.isSecurity(key)
861 ? makeSecurityMiddleware(key, service)
862 : service
863 handler = apply(handler, options)
864 }
865 return handler
866}
867
868const securityMiddlewareCache = new WeakMap<
869 object,

Callers 1

handlerToHttpEffectFunction · 0.70

Calls 3

makeSecurityMiddlewareFunction · 0.85
getUnsafeMethod · 0.80
applyFunction · 0.50

Tested by

no test coverage detected