跳转到正文

Dev 辅助工具 ​

Dev 辅助工具提供开发过程中实用的方法。

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

getRouterName() ​

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

ts
const app = new Hono()

// ...

console.log(getRouterName(app))

showRoutes() ​

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

假设有以下应用:

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

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

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

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

showRoutes(app, {
  verbose: true,
})

应用启动时,控制台会显示以下路由信息:

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

选项 ​

optional verbose: boolean ​

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

optional colorize: boolean ​

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

基于 MIT 许可证发布。