@@ -179,20 +179,17 @@ class API {
179
179
methods . forEach ( ( _method ) => {
180
180
// Method must be a string
181
181
if ( typeof _method === 'string' ) {
182
- // Check for wild card at this level
183
- if ( routes [ 'ROUTES' ] [ '*' ] ) {
182
+ const wildcardForPathLevel = routes [ i ] == '' ? routes [ 'ROUTES' ] [ '*' ] : routes [ 'ROUTES' ] [ route [ i ] ] [ '*' ] ;
183
+ if ( wildcardForPathLevel != null ) {
184
184
if (
185
- routes [ 'ROUTES' ] [ '*' ] [ 'MIDDLEWARE' ] &&
185
+ wildcardForPathLevel [ 'MIDDLEWARE' ] &&
186
186
( route [ i ] !== '*' || _method !== '__MW__' )
187
187
) {
188
- _stack [ '*' ] [ method ] = routes [ 'ROUTES' ] [ '*' ] [ 'MIDDLEWARE' ] . stack ;
188
+ _stack [ '*' ] [ method ] = wildcardForPathLevel [ 'MIDDLEWARE' ] . stack ;
189
189
}
190
- if (
191
- routes [ 'ROUTES' ] [ '*' ] [ 'METHODS' ] &&
192
- routes [ 'ROUTES' ] [ '*' ] [ 'METHODS' ] [ method ]
193
- ) {
190
+ if ( wildcardForPathLevel ?. [ 'METHODS' ] ?. [ method ] != null ) {
194
191
_stack [ 'm' ] [ method ] =
195
- routes [ 'ROUTES' ] [ '*' ] [ 'METHODS' ] [ method ] . stack ;
192
+ wildcardForPathLevel [ 'METHODS' ] [ method ] . stack ;
196
193
}
197
194
} // end if wild card
198
195
@@ -216,13 +213,12 @@ class API {
216
213
: _stack [ '*' ] [ method ]
217
214
? _stack [ '*' ] [ method ] . concat ( stack )
218
215
: stack ,
219
- // inherited: _stack[method] ? _stack[method] : [],
220
216
route : '/' + parsedPath . join ( '/' ) ,
221
217
path : '/' + this . _prefix . concat ( parsedPath ) . join ( '/' ) ,
222
218
} ;
223
219
224
- // If mounting middleware
225
- if ( method === '__MW__' ) {
220
+ const isMountingMiddleware = _method === '__MW__' ;
221
+ if ( isMountingMiddleware ) {
226
222
// Merge stacks if middleware exists
227
223
if ( routes [ 'ROUTES' ] [ route [ i ] ] [ 'MIDDLEWARE' ] ) {
228
224
meta . stack =
@@ -234,17 +230,6 @@ class API {
234
230
}
235
231
// Add/update middleware
236
232
routes [ 'ROUTES' ] [ route [ i ] ] [ 'MIDDLEWARE' ] = meta ;
237
-
238
- // Apply middleware to all child middlware routes
239
- // if (route[i] === "*") {
240
- // // console.log("APPLY NESTED MIDDLEWARE");
241
- // // console.log(JSON.stringify(routes["ROUTES"], null, 2));
242
- // Object.keys(routes["ROUTES"]).forEach((nestedRoute) => {
243
- // if (nestedRoute != "*") {
244
- // console.log(nestedRoute);
245
- // }
246
- // });
247
- // }
248
233
} else {
249
234
// Create the methods section if it doesn't exist
250
235
if ( ! routes [ 'ROUTES' ] [ route [ i ] ] [ 'METHODS' ] )
@@ -266,8 +251,6 @@ class API {
266
251
routes [ 'ROUTES' ] [ route [ i ] ] [ 'METHODS' ] [ _method ] = meta ;
267
252
} // end else
268
253
269
- // console.log('STACK:',meta);
270
-
271
254
// If there's a wild card that's not at the end
272
255
} else if ( route [ i ] === '*' ) {
273
256
throw new ConfigurationError (
0 commit comments