-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.d.ts
42 lines (34 loc) · 1.44 KB
/
common.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Pattern, Methods } from 'trouter'
export interface IRouterConfig {
defaultRoute?: RequestHandler
errorHandler?: (err: Error) => Response | Promise<Response>
port?: number
}
export type StepFunction = (error?: unknown) => Response | Promise<Response>
type ZeroRequest = Request & {
params: Record<string, string>
query: Record<string, string>
ctx?: Record<string, any>
}
export type RequestHandler = (
req: ZeroRequest,
next: StepFunction
) => Response | Promise<Response>
export interface IRouter {
fetch: (req: Request) => Response | Promise<Response>
use(...handlers: RequestHandler[]): this
use(router: IRouter): this
use(pattern: Pattern, ...handlers: RequestHandler[]): this
use(prefix: Pattern, router: IRouter): this
on(method: Methods, pattern: Pattern, ...middlewares: RequestHandler[]): this
all(pattern: Pattern, ...handlers: RequestHandler[]): this
get(pattern: Pattern, ...handlers: RequestHandler[]): this
head(pattern: Pattern, ...handlers: RequestHandler[]): this
patch(pattern: Pattern, ...handlers: RequestHandler[]): this
options(pattern: Pattern, ...handlers: RequestHandler[]): this
connect(pattern: Pattern, ...handlers: RequestHandler[]): this
delete(pattern: Pattern, ...handlers: RequestHandler[]): this
trace(pattern: Pattern, ...handlers: RequestHandler[]): this
post(pattern: Pattern, ...handlers: RequestHandler[]): this
put(pattern: Pattern, ...handlers: RequestHandler[]): this
}