UNPKG

hono

Version:

Web framework built on Web Standards

68 lines (67 loc) 1.75 kB
import type { Context } from '../../context'; import type { RouterRoute } from '../../types'; /** * Get matched routes in the handler * * @param {Context} c - The context object * @returns An array of matched routes * * @example * ```ts * import { matchedRoutes } from 'hono/route' * * app.use('*', async function logger(c, next) { * await next() * matchedRoutes(c).forEach(({ handler, method, path }, i) => { * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]') * console.log( * method, * ' ', * path, * ' '.repeat(Math.max(10 - path.length, 0)), * name, * i === c.req.routeIndex ? '<- respond from here' : '' * ) * }) * }) * ``` */ export declare const matchedRoutes: (c: Context) => RouterRoute[]; /** * Get the route path registered within the handler * * @param {Context} c - The context object * @returns The route path registered within the handler * * @example * ```ts * import { routePath } from 'hono/route' * * app.get('/posts/:id', (c) => { * return c.text(routePath(c)) // '/posts/:id' * }) * ``` */ export declare const routePath: (c: Context) => string; /** * Get the basePath of the as-is route specified by routing. * * @param {Context} c - The context object * @returns The basePath of the as-is route specified by routing. * * @example * ```ts * import { baseRoutePath } from 'hono/route' * * const app = new Hono() * * const subApp = new Hono() * subApp.get('/posts/:id', (c) => { * return c.text(baseRoutePath(c)) // '/:sub' * }) * * app.route('/:sub', subApp) * ``` */ export declare const baseRoutePath: (c: Context) => string; export declare const basePath: (c: Context) => string;