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

Function applyMiddleware

packages/effect/src/http-api/HttpApiBuilder.ts:1096–1112  ·  view source on GitHub ↗
(
  group: Group,
  endpoint: HttpApiEndpoint.Top,
  context: Context.Context<any>,
  handler: A
)

Source from the content-addressed store, hash-verified

1094}
1095
1096const applyMiddleware = <Group extends HttpApiGroup.Constraint, A extends Effect.Effect<any, any, any>>(
1097 group: Group,
1098 endpoint: HttpApiEndpoint.Top,
1099 context: Context.Context<any>,
1100 handler: A
1101) => {
1102 const options = { group, endpoint }
1103 for (const key_ of endpoint.middlewares) {
1104 const key = key_ as HttpApiMiddleware.AnyService
1105 const service = Context.getUnsafe(context, key)
1106 const apply = HttpApiMiddleware.isSecurity(key)
1107 ? makeSecurityMiddleware(key, service)
1108 : service
1109 handler = apply(handler, options)
1110 }
1111 return handler
1112}
1113
1114const securityMiddlewareCache = new WeakMap<
1115 object,

Callers 1

handlerToHttpEffectFunction · 0.70

Calls 3

makeSecurityMiddlewareFunction · 0.85
applyFunction · 0.70
getUnsafeMethod · 0.45

Tested by

no test coverage detected