開發輔助工具
開發輔助工具提供您在開發過程中可以使用的實用方法。
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
選項
可選 verbose: boolean
設定為 true
時,會顯示詳細資訊。
可選 colorize: boolean
設定為 false
時,輸出將不會有顏色。