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

Method handle

packages/app/src/app.ts:295–315  ·  view source on GitHub ↗
(mw: Middleware)

Source from the content-addressed store, hash-verified

293 })
294
295 const handle = (mw: Middleware) => async (req: Req, res: Res, next?: NextFunction) => {
296 const { path, handler, type, regex } = mw
297
298 const params = regex ? getURLParams(regex, pathname) : {}
299
300 if (type === 'route') req.params = params
301
302 if (path.includes(':')) {
303 const url = req.url.slice(req.url.indexOf(Object.values(params)[0]) + Object.values(params)[0].length)
304
305 req.url = lead(url)
306 } else {
307 req.url = lead(req.url.substring(path.length))
308 }
309
310 req.path = getPathname(req.url)
311
312 if (this.settings?.enableReqRoute) req.route = getRouteFromApp(this as any, handler)
313
314 await applyHandler<Req, Res>((handler as unknown) as Handler<Req, Res>)(req, res, next)
315 }
316
317 let idx = 0
318

Callers

nothing calls this directly

Calls 4

getRouteFromAppFunction · 0.90
getURLParamsFunction · 0.85
leadFunction · 0.85
getPathnameFunction · 0.85

Tested by

no test coverage detected