Skip to content

Commit

Permalink
fix: enhance path matching to include matched parameters in sagContext (
Browse files Browse the repository at this point in the history
  • Loading branch information
irensaltali authored Nov 13, 2024
1 parent 3ac1319 commit 3213dfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default {
return 0; // Equal priority
})[0];

sagContext.matchedPath = matchedPath;

if (matchedPath) {
// Check if the matched path requires authorization
if (sagContext.apiConfig.authorizer && matchedPath.config.auth && sagContext.apiConfig.authorizer.type == 'jwt') {
Expand Down
5 changes: 5 additions & 0 deletions src/path-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class PathOperator {
return { matchedCount: 0, isExact: false, isWildcard: false, methodMatches: methodMatches };
}

const params = {}; // Initialize an empty object to store parameters

for (let i = 0; i < Math.max(configSegments.length, requestSegments.length); i++) {
if (i < configSegments.length && this.isWildcard(configSegments[i])) {
isWildcardUsed = true;
Expand All @@ -45,6 +47,8 @@ export class PathOperator {

if (this.isParam(configSegments[i])) {
isExact = false; // Found a parameterized segment, so it's not an exact match
const paramName = configSegments[i].slice(1, -1); // Extract the parameter name without the first and last character
params[paramName] = requestSegments[i]; // Store the parameter value
matchedSegments++;
} else if (configSegments[i] === requestSegments[i]) {
matchedSegments++; // Exact match for this segment
Expand All @@ -58,6 +62,7 @@ export class PathOperator {
isExact: isExact && matchedSegments === configSegments.length && matchedSegments === requestSegments.length,
isWildcard: isWildcardUsed,
methodMatches: methodMatches, // Include method match status
params: params, // Include the parameters in the result
};
}
}

0 comments on commit 3213dfc

Please sign in to comment.