Skip to content

预设

¥Presets

Hono 有多个路由,每个路由都为特定目的而设计。你可以在 Hono 的构造函数中指定要使用的路由。

¥Hono has several routers, each designed for a specific purpose. You can specify the router you want to use in the constructor of Hono.

为常见用例提供了预设,因此你不必每次都指定路由。从所有预设导入的 Hono 类是相同的,唯一的区别是路由。因此,你可以互换使用它们。

¥Presets are provided for common use cases, so you don't have to specify the router each time. The Hono class imported from all presets is the same, the only difference being the router. Therefore, you can use them interchangeably.

hono

用法:

¥Usage:

ts
import { 
Hono
} from 'hono'

路由:

¥Routers:

ts
this.router = new SmartRouter({
  routers: [new RegExpRouter(), new TrieRouter()],
})

hono/quick

用法:

¥Usage:

ts
import { 
Hono
} from 'hono/quick'

路由:

¥Router:

ts
this.router = new SmartRouter({
  routers: [new LinearRouter(), new TrieRouter()],
})

hono/tiny

用法:

¥Usage:

ts
import { 
Hono
} from 'hono/tiny'

路由:

¥Router:

ts
this.router = new PatternRouter()

我应该使用哪个预设?

¥Which preset should I use?

预设适用平台
hono对于大多数用例,强烈建议这样做。虽然注册阶段可能比 hono/quick 慢,但一旦启动,它就会表现出高性能。它是使用 Deno、Bun 或 Node.js 构建的长寿命服务器的理想选择。对于使用 v8 隔离的环境(例如 Cloudflare Workers、Deno Deploy),此预设也适用。因为隔离在启动后会持续一段时间。
hono/quick此预设专为应用为每个请求初始化的环境而设计。Fastly Compute 以这种方式运行,因此建议使用此预设。
hono/tiny这是最小的路由包,适用于资源有限的环境。

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