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() 函数在你的控制台中显示已注册的路由。

考虑如下应用:

🌐 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 详细: boolean

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

🌐 When set to true, it displays verbose information.

optional 上色: boolean

当设置为 false 时,输出将不会有颜色。

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

Hono 中文网 - 粤ICP备13048890号