@@ -160,14 +160,17 @@ export const asAsync = <Router extends IRouter | RouterT<any, any>>(
160
160
) : Router => {
161
161
return new Proxy ( router , {
162
162
get ( target , prop , receiver ) {
163
+ // o is the original method of the provided router
163
164
const o = Reflect . get ( target , prop , receiver ) ;
164
- if ( typeof prop !== "string" ) {
165
- return o ;
166
- }
167
- if ( ! [ ...Method , "all" ] . includes ( prop ) ) {
168
- return o ;
169
- }
170
- if ( typeof o !== "function" ) {
165
+ if (
166
+ // prop may be string or symbol. We only want to wrap string methods.
167
+ typeof prop !== "string" ||
168
+ // We only wrap methods that are represents HTTP methods.
169
+ ! [ ...Method , "all" ] . includes ( prop ) ||
170
+ // If `prop` is one of the HTTP methods, `o` should be a function, but we check just to be sure.
171
+ typeof o !== "function"
172
+ ) {
173
+ // If it's not a method we want to wrap, just return the original method.
171
174
return o ;
172
175
}
173
176
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -178,6 +181,7 @@ export const asAsync = <Router extends IRouter | RouterT<any, any>>(
178
181
}
179
182
const handlers = args
180
183
. slice ( 1 )
184
+ // wrap all middleware and handlers
181
185
. map ( ( h ) => ( typeof h === "function" ? wrap ( h ) : h ) ) ;
182
186
// eslint-disable-next-line @typescript-eslint/no-explicit-any
183
187
return o . apply ( target , [ args [ 0 ] , ...handlers ] as any ) ;
0 commit comments