Skip to content

开发助手

¥Dev Helper

Dev Helper 提供了你可以在开发中使用的有用方法。

¥Dev Helper provides useful methods you can use in development.

ts
import { Hono } from 'hono'
import { getRouterName, showRoutes } from 'hono/dev'

getRouterName()

你可以使用 getRouterName() 获取当前使用的路由的名称。

¥You can get the name of the currently used router with getRouterName().

ts
const app = new Hono()

// ...

console.log(getRouterName(app))

showRoutes()

showRoutes() 函数在你的控制台中显示已注册的路由。

¥showRoutes() function displays the registered routes in your console.

考虑如下应用:

¥Consider an application like the following:

ts
const app = new Hono().basePath('/v1')

app.get('/posts', (c) => {
  // ...
})

app.get('/posts/:id', (c) => {
  // ...
})

app.post('/posts', (c) => {
  // ...
})

showRoutes(app, {
  verbose: true,
})

当此应用开始运行时,路由将显示在你的控制台中,如下所示:

¥When this application starts running, the routes will be shown in your console as follows:

txt
GET   /v1/posts
GET   /v1/posts/:id
POST  /v1/posts

选项

¥Options

optional verbose:boolean

设置为 true 时,显示详细信息。

¥When set to true, it displays verbose information.

optional colorize:boolean

设置为 false 时,输出不会带颜色。

¥When set to false, the output will not be colored.

Hono v4.7 中文网 - 粤ICP备13048890号