2023-04-26 03:15:45 +02:00
|
|
|
import { HonoBase } from './hono-base'
|
2023-10-16 23:36:09 +02:00
|
|
|
import type { HonoOptions } from './hono-base'
|
2022-09-12 13:49:18 +02:00
|
|
|
import { RegExpRouter } from './router/reg-exp-router'
|
|
|
|
import { SmartRouter } from './router/smart-router'
|
|
|
|
import { TrieRouter } from './router/trie-router'
|
2024-05-29 10:41:53 +02:00
|
|
|
import type { BlankEnv, BlankSchema, Env, Schema } from './types'
|
2022-05-16 14:33:15 +02:00
|
|
|
|
2024-05-29 10:38:11 +02:00
|
|
|
/**
|
|
|
|
* The Hono class extends the functionality of the HonoBase class.
|
|
|
|
* It sets up routing and allows for custom options to be passed.
|
|
|
|
*
|
|
|
|
* @template E - The environment type.
|
|
|
|
* @template S - The schema type.
|
|
|
|
* @template BasePath - The base path type.
|
|
|
|
*/
|
2023-08-24 08:36:49 +02:00
|
|
|
export class Hono<
|
2024-05-29 10:41:53 +02:00
|
|
|
E extends Env = BlankEnv,
|
2024-01-20 00:59:45 +01:00
|
|
|
S extends Schema = BlankSchema,
|
2023-08-24 08:36:49 +02:00
|
|
|
BasePath extends string = '/'
|
|
|
|
> extends HonoBase<E, S, BasePath> {
|
2024-05-29 10:38:11 +02:00
|
|
|
/**
|
|
|
|
* Creates an instance of the Hono class.
|
|
|
|
*
|
|
|
|
* @param options - Optional configuration options for the Hono instance.
|
|
|
|
*/
|
2023-10-16 23:36:09 +02:00
|
|
|
constructor(options: HonoOptions<E> = {}) {
|
|
|
|
super(options)
|
2023-05-09 14:50:43 +02:00
|
|
|
this.router =
|
2023-10-16 23:36:09 +02:00
|
|
|
options.router ??
|
2023-05-09 14:50:43 +02:00
|
|
|
new SmartRouter({
|
|
|
|
routers: [new RegExpRouter(), new TrieRouter()],
|
|
|
|
})
|
2022-03-10 07:44:09 +01:00
|
|
|
}
|
2022-01-05 10:41:29 +01:00
|
|
|
}
|