-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.ts
57 lines (48 loc) · 1.23 KB
/
types.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { DummyResponse, THResponse } from './response.ts'
import { METHODS } from './constants.ts'
import { THRequest } from './request.ts'
type Method = typeof METHODS[number]
type Protocol = 'http' | 'https'
/**
* tinyhttp App has a few settings for toggling features
*/
type AppSettings = Partial<
& Record<'bindAppToReqRes' | 'enableReqRoute', boolean>
& Record<'subdomainOffset', number>
& Record<'xPoweredBy', string | boolean>
>
type AppConstructor<Req, Res> = Partial<{
noMatchHandler: Handler
onError: (err: unknown, req?: Request) => Response | Promise<Response>
applyExtensions: (req: Req, res: Res, next: NextFunction) => void
settings: AppSettings
}>
type NextFunction = (e?: unknown) => void | Promise<void>
type Handler<
Req extends Request = THRequest,
Res extends DummyResponse = THResponse,
> = (
req: Req,
res: Res,
next: NextFunction,
) => void | Promise<void>
type Middleware<
Req extends THRequest = THRequest,
Res extends THResponse = THResponse,
> = {
handler: Handler<Req, Res>
type: 'mw' | 'route'
path?: string
method?: Method
fullPath?: string
pattern?: URLPattern
}
export type {
AppConstructor,
AppSettings,
Handler,
Method,
Middleware,
NextFunction,
Protocol,
}