Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Aug 17, 2024
1 parent 1a805bf commit 18f0d7c
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,17 @@ class API {
methods.forEach((_method) => {
// Method must be a string
if (typeof _method === 'string') {
// Check for wild card at this level
if (routes['ROUTES']['*']) {
const wildcardForPathLevel = routes[i] == '' ? routes['ROUTES']['*'] : routes['ROUTES'][route[i]]['*'];
if (wildcardForPathLevel != null) {
if (
routes['ROUTES']['*']['MIDDLEWARE'] &&
wildcardForPathLevel['MIDDLEWARE'] &&
(route[i] !== '*' || _method !== '__MW__')
) {
_stack['*'][method] = routes['ROUTES']['*']['MIDDLEWARE'].stack;
_stack['*'][method] = wildcardForPathLevel['MIDDLEWARE'].stack;
}
if (
routes['ROUTES']['*']['METHODS'] &&
routes['ROUTES']['*']['METHODS'][method]
) {
if (wildcardForPathLevel?.['METHODS']?.[method] != null) {
_stack['m'][method] =
routes['ROUTES']['*']['METHODS'][method].stack;
wildcardForPathLevel['METHODS'][method].stack;
}
} // end if wild card

Expand All @@ -216,13 +213,12 @@ class API {
: _stack['*'][method]
? _stack['*'][method].concat(stack)
: stack,
// inherited: _stack[method] ? _stack[method] : [],
route: '/' + parsedPath.join('/'),
path: '/' + this._prefix.concat(parsedPath).join('/'),
};

// If mounting middleware
if (method === '__MW__') {
const isMountingMiddleware = _method === '__MW__';
if (isMountingMiddleware) {
// Merge stacks if middleware exists
if (routes['ROUTES'][route[i]]['MIDDLEWARE']) {
meta.stack =
Expand All @@ -234,17 +230,6 @@ class API {
}
// Add/update middleware
routes['ROUTES'][route[i]]['MIDDLEWARE'] = meta;

// Apply middleware to all child middlware routes
// if (route[i] === "*") {
// // console.log("APPLY NESTED MIDDLEWARE");
// // console.log(JSON.stringify(routes["ROUTES"], null, 2));
// Object.keys(routes["ROUTES"]).forEach((nestedRoute) => {
// if (nestedRoute != "*") {
// console.log(nestedRoute);
// }
// });
// }
} else {
// Create the methods section if it doesn't exist
if (!routes['ROUTES'][route[i]]['METHODS'])
Expand All @@ -266,8 +251,6 @@ class API {
routes['ROUTES'][route[i]]['METHODS'][_method] = meta;
} // end else

// console.log('STACK:',meta);

// If there's a wild card that's not at the end
} else if (route[i] === '*') {
throw new ConfigurationError(
Expand Down

0 comments on commit 18f0d7c

Please sign in to comment.