Skip to content

预设

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

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

hono

用法:

ts
import { 
Hono
} from 'hono'

路由器:

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

hono/quick

用法:

ts
import { 
Hono
} from 'hono/quick'

路由器:

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

hono/tiny

用法:

ts
import { 
Hono
} from 'hono/tiny'

路由器:

ts
this.router = new PatternRouter()

我应该使用哪个预设?

预设适用平台
hono强烈建议在大多数用例中使用此预设。虽然注册阶段可能比 hono/quick 慢,但一旦启动,它就会表现出高性能。它非常适合使用 DenoBunNode.js 构建的长寿命服务器。它也适用于 Fastly Compute,因为在该平台上,路由注册发生在应用构建阶段。对于 Cloudflare WorkersDeno Deploy 等使用 v8 隔离的环境,此预设也同样适用。因为隔离在启动后会持续一段时间。
hono/quick此预设专为每次请求都初始化应用程序的环境而设计。
hono/tiny这是最小的路由器包,适用于资源有限的环境。

Released under the MIT License.