new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Hono · all subjects

helpers/route

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Route helper imports

The route helper functions are imported from 'hono/route'. The available functions are: matchedRoutes, routePath, baseRoutePath, and basePath.

matchedRoutes() returns array of matched routes

matchedRoutes(c) returns an array of all routes that matched the current request, including middleware. Each matched route object contains method, path, and handler properties.

routePath() returns current route pattern

routePath(c) returns the route path pattern registered for the current handler. It accepts an optional index parameter to get the route path at a specific position, similar to Array.prototype.at(). For example, routePath(c, 0) returns the first matched route and routePath(c, -1) returns the last matched route.

baseRoutePath() returns base path pattern

baseRoutePath(c) returns the base path pattern of the current route as specified in routing. It accepts an optional index parameter to get the base route path at a specific position, similar to Array.prototype.at().

basePath() returns base path with embedded parameters

basePath(c) returns the base path with embedded parameters from the actual request. For example, if a sub-application is routed at '/:sub' and receives a request to '/api/posts/123', basePath(c) returns '/api'.

Route helper for debugging and middleware development

The Route Helper provides enhanced routing information for debugging and middleware development. It allows you to access detailed information about matched routes and the current route being processed.

matchedRoutes example with middleware

Example showing matchedRoutes() including middleware: ```ts app.all('/api/*', (c, next) => { console.log('API middleware') return next() }) app.get('/api/users/:id', (c) => { const routes = matchedRoutes(c) // Returns: [ // { method: 'ALL', path: '/api/*', handler: [Function] }, // { method: 'GET', path: '/api/users/:id', handler: [Function] } // ] return c.json({ routes: routes.length }) }) ```

routePath with index parameter example

Example showing routePath() with index parameter: ```ts app.all('/api/*', (c, next) => { return next() }) app.get('/api/users/:id', (c) => { console.log(routePath(c, 0)) // '/api/*' (first matched route) console.log(routePath(c, -1)) // '/api/users/:id' (last matched route) return c.text('User details') }) ```

baseRoutePath with index parameter example

Example showing baseRoutePath() with index parameter: ```ts app.all('/api/*', (c, next) => { return next() }) const subApp = new Hono() subApp.get('/users/:id', (c) => { console.log(baseRoutePath(c, 0)) // '/' (first matched route) console.log(baseRoutePath(c, -1)) // '/api' (last matched route) return c.text('User details') }) app.route('/api', subApp) ```

Give your agent this brain