Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimon committed Nov 1, 2024
1 parent cab5fc9 commit 99c9fce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/express/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ const getRoutePath = (req: Request) => {
return;
}
if (req.baseUrl) {
const routerPaths = getRouterPaths(req.app._router.stack, req.baseUrl);
return routerPaths.join("") + req.route.path;
const routerPath = getRouterPath(req.app._router.stack, req.baseUrl);
return routerPath + req.route.path;
}
return req.route.path;
};

const getRouterPaths = (stack: any[], baseUrl: string) => {
const getRouterPath = (stack: any[], baseUrl: string) => {
const routerPaths: string[] = [];
while (stack && stack.length > 0) {
const routerLayer = stack.find(
Expand All @@ -165,7 +165,7 @@ const getRouterPaths = (stack: any[], baseUrl: string) => {
break;
}
}
return routerPaths;
return routerPaths.join("");
};

const getConsumer = (req: Request) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/express/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe("Middleware for Express with nested routers", () => {

it("Request logger", async () => {
await appTest.get("/api/v1/hello/bob").expect(200);
await appTest.get("/api/v1/goodbye/world").expect(200);
await appTest.get("/api/v2/goodbye/world").expect(200);

const requests = client.requestCounter.getAndResetRequests();
expect(requests.length).toBe(2);
Expand Down

0 comments on commit 99c9fce

Please sign in to comment.