Skip to content

Commit edd5eaf

Browse files
committed
fix: middleware applied twice
1 parent 9fa3d93 commit edd5eaf

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/core/middleware/route-info-path-extractor.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ export class RouteInfoPathExtractor {
3434

3535
if (this.isAWildcard(path)) {
3636
const prefix = addLeadingSlash(this.prefixPath + versionPath);
37-
const basePaths = prefix
38-
? [prefix, prefix + addLeadingSlash(path)]
39-
: [addLeadingSlash(path)];
4037
return Array.isArray(this.excludedGlobalPrefixRoutes)
4138
? [
42-
...basePaths,
39+
prefix,
4340
...this.excludedGlobalPrefixRoutes.map(
4441
route => versionPath + addLeadingSlash(route.path),
4542
),
4643
]
47-
: basePaths;
44+
: [prefix];
4845
}
4946

5047
return [this.extractNonWildcardPathFrom({ path, method, version })];

packages/core/test/middleware/route-info-path-extractor.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ describe('RouteInfoPathExtractor', () => {
2323
path: '*',
2424
method: RequestMethod.ALL,
2525
}),
26-
).to.eql(['/*']);
26+
).to.eql(['']);
2727

2828
expect(
2929
routeInfoPathExtractor.extractPathsFrom({
3030
path: '*',
3131
method: RequestMethod.ALL,
3232
version: '1',
3333
}),
34-
).to.eql(['/v1', '/v1/*']);
34+
).to.eql(['/v1']);
3535
});
3636

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

4747
expect(
4848
routeInfoPathExtractor.extractPathsFrom({
4949
path: '*',
5050
method: RequestMethod.ALL,
5151
version: '1',
5252
}),
53-
).to.eql(['/api/v1', '/api/v1/*']);
53+
).to.eql(['/api/v1']);
5454
});
5555

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

7171
expect(
7272
routeInfoPathExtractor.extractPathsFrom({
7373
path: '*',
7474
method: RequestMethod.ALL,
7575
version: '1',
7676
}),
77-
).to.eql(['/api/v1', '/api/v1/*', '/v1/foo']);
77+
).to.eql(['/api/v1', '/v1/foo']);
7878

7979
expect(
8080
routeInfoPathExtractor.extractPathsFrom({

0 commit comments

Comments
 (0)