MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / use

Method use

packages/router/src/index.ts:263–287  ·  view source on GitHub ↗

* Push middleware to the stack

(...args: UseMethodParams<Req, Res, App>)

Source from the content-addressed store, hash-verified

261 * Push middleware to the stack
262 */
263 use(...args: UseMethodParams<Req, Res, App>) {
264 const base = args[0]
265
266 const handlers = args.slice(1).flat()
267
268 if (typeof base === 'string') {
269 pushMiddleware(this.middleware)({
270 path: base,
271 handler: handlers[0] as Handler,
272 handlers: handlers.slice(1) as Handler[],
273 type: 'mw'
274 })
275 } else {
276 pushMiddleware(this.middleware)({
277 path: '/',
278 handler: Array.isArray(base) ? base[0] : (base as Handler),
279 handlers: Array.isArray(base)
280 ? [...(base.slice(1) as Handler[]), ...(handlers as Handler[])]
281 : (handlers as Handler[]),
282 type: 'mw'
283 })
284 }
285
286 return this
287 }
288}

Callers

nothing calls this directly

Calls 1

pushMiddlewareFunction · 0.85

Tested by

no test coverage detected