MCPcopy Index your code
hub / github.com/upstash/jstack / middlewareHandler

Method middlewareHandler

packages/jstack/src/server/router.ts:221–244  ·  view source on GitHub ↗
(c: Context<E>, next: Next)

Source from the content-addressed store, hash-verified

219 const operationMiddlewares: MiddlewareHandler<E>[] =
220 operation.middlewares.map((middleware) => {
221 const middlewareHandler = async (c: Context<E>, next: Next) => {
222 const typedC = c as ContextWithSuperJSON<
223 E & { Variables: InternalContext }
224 >
225 let middlewareOutput = typedC.get("__middleware_output") ?? {}
226
227 const nextWrapper = async <B>(args: B) => {
228 Object.assign(middlewareOutput, args)
229 return middlewareOutput
230 }
231
232 const res = await middleware({
233 ctx: middlewareOutput,
234 next: nextWrapper,
235 c: c as ContextWithSuperJSON<E>,
236 })
237
238 if (res) {
239 Object.assign(middlewareOutput, res)
240 }
241
242 typedC.set("__middleware_output", middlewareOutput)
243 await next()
244 }
245
246 return middlewareHandler
247 })

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected