Skip to content

Commit

Permalink
fix: middleware applied twice
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Aug 24, 2023
1 parent 9fa3d93 commit edd5eaf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 2 additions & 5 deletions packages/core/middleware/route-info-path-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ export class RouteInfoPathExtractor {

if (this.isAWildcard(path)) {
const prefix = addLeadingSlash(this.prefixPath + versionPath);
const basePaths = prefix
? [prefix, prefix + addLeadingSlash(path)]
: [addLeadingSlash(path)];
return Array.isArray(this.excludedGlobalPrefixRoutes)
? [
...basePaths,
prefix,
...this.excludedGlobalPrefixRoutes.map(
route => versionPath + addLeadingSlash(route.path),
),
]
: basePaths;
: [prefix];
}

return [this.extractNonWildcardPathFrom({ path, method, version })];
Expand Down
12 changes: 6 additions & 6 deletions packages/core/test/middleware/route-info-path-extractor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ describe('RouteInfoPathExtractor', () => {
path: '*',
method: RequestMethod.ALL,
}),
).to.eql(['/*']);
).to.eql(['']);

expect(
routeInfoPathExtractor.extractPathsFrom({
path: '*',
method: RequestMethod.ALL,
version: '1',
}),
).to.eql(['/v1', '/v1/*']);
).to.eql(['/v1']);
});

it(`should return correct paths when set global prefix`, () => {
Expand All @@ -42,15 +42,15 @@ describe('RouteInfoPathExtractor', () => {
path: '*',
method: RequestMethod.ALL,
}),
).to.eql(['/api', '/api/*']);
).to.eql(['/api']);

expect(
routeInfoPathExtractor.extractPathsFrom({
path: '*',
method: RequestMethod.ALL,
version: '1',
}),
).to.eql(['/api/v1', '/api/v1/*']);
).to.eql(['/api/v1']);
});

it(`should return correct paths when set global prefix and global prefix options`, () => {
Expand All @@ -66,15 +66,15 @@ describe('RouteInfoPathExtractor', () => {
path: '*',
method: RequestMethod.ALL,
}),
).to.eql(['/api', '/api/*', '/foo']);
).to.eql(['/api', '/foo']);

expect(
routeInfoPathExtractor.extractPathsFrom({
path: '*',
method: RequestMethod.ALL,
version: '1',
}),
).to.eql(['/api/v1', '/api/v1/*', '/v1/foo']);
).to.eql(['/api/v1', '/v1/foo']);

expect(
routeInfoPathExtractor.extractPathsFrom({
Expand Down

0 comments on commit edd5eaf

Please sign in to comment.