@@ -22,38 +22,38 @@ declare global {
22
22
}
23
23
}
24
24
25
- export const renderTemplate = < O = any , Res extends Response = Response > ( res : Res , app : App ) => (
26
- file : string ,
27
- data ?: Record < string , any > ,
28
- options ?: TemplateEngineOptions < O >
29
- ) : Response => {
30
- app . render (
31
- file ,
32
- data ,
33
- ( err : unknown , html : unknown ) => {
34
- if ( err ) throw err
35
-
36
- res . send ( html )
37
- } ,
38
- options
39
- )
40
-
41
- return res
42
- }
25
+ export const renderTemplate =
26
+ < O = any , Res extends Response = Response > ( res : Res , app : App ) =>
27
+ ( file : string , data ?: Record < string , any > , options ?: TemplateEngineOptions < O > ) : Response => {
28
+ app . render (
29
+ file ,
30
+ data ,
31
+ ( err : unknown , html : unknown ) => {
32
+ if ( err ) throw err
33
+
34
+ res . send ( html )
35
+ } ,
36
+ options
37
+ )
38
+
39
+ return res
40
+ }
43
41
44
42
/**
45
43
* Execute handler with passed `req` and `res`. Catches errors and resolves async handlers.
46
44
* @param h
47
45
*/
48
- export const applyHandler = < Req , Res > ( h : Handler < Req , Res > ) => async ( req : Req , res : Res , next : NextFunction ) => {
49
- try {
50
- if ( h . constructor . name === 'AsyncFunction' ) {
51
- await h ( req , res , next )
52
- } else h ( req , res , next )
53
- } catch ( e ) {
54
- next ( e )
46
+ export const applyHandler =
47
+ < Req , Res > ( h : Handler < Req , Res > ) =>
48
+ async ( req : Req , res : Res , next : NextFunction ) => {
49
+ try {
50
+ if ( h . constructor . name === 'AsyncFunction' ) {
51
+ await h ( req , res , next )
52
+ } else h ( req , res , next )
53
+ } catch ( e ) {
54
+ next ( e )
55
+ }
55
56
}
56
- }
57
57
58
58
/**
59
59
* tinyhttp App has a few settings for toggling features
@@ -119,7 +119,8 @@ export class App<
119
119
Res extends Response < RenderOptions > = Response < RenderOptions >
120
120
>
121
121
extends Router < App , Req , Res >
122
- implements tinyhttp . Application {
122
+ implements tinyhttp . Application
123
+ {
123
124
middleware : Middleware < Req > [ ] = [ ]
124
125
locals : Record < string , string > = { }
125
126
noMatchHandler : Handler
@@ -221,7 +222,7 @@ export class App<
221
222
222
223
const path = typeof base === 'string' ? base : '/'
223
224
224
- let regex : { keys : string [ ] ; pattern : RegExp } | undefined
225
+ let regex : { keys : string [ ] | boolean ; pattern : RegExp } | undefined
225
226
226
227
for ( const fn of fns ) {
227
228
if ( fn instanceof App ) {
@@ -312,14 +313,14 @@ export class App<
312
313
313
314
if ( type === 'route' ) req . params = getURLParams ( regex , pathname )
314
315
315
- await applyHandler < Req , Res > ( ( handler as unknown ) as Handler < Req , Res > ) ( req , res , next )
316
+ await applyHandler < Req , Res > ( handler as unknown as Handler < Req , Res > ) ( req , res , next )
316
317
}
317
318
318
319
let idx = 0
319
320
320
321
next = next || ( ( err : any ) => ( err ? this . onError ( err , req ) : loop ( ) ) )
321
322
322
- const loop = ( ) => idx < mw . length && handle ( mw [ idx ++ ] ) ( req , ( res as unknown ) as Res , next as NextFunction )
323
+ const loop = ( ) => idx < mw . length && handle ( mw [ idx ++ ] ) ( req , res as unknown as Res , next as NextFunction )
323
324
324
325
loop ( )
325
326
0 commit comments