Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/express-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ class ExpressMiddleware {
}
}

// nest.js - build request url pattern if exists
if (typeof req.params === 'object') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm 100% with not mutating this object, but i guess we rely on it and it should be handled in the relevant place. i guess when we publish metrics

Object.keys(req.params).forEach((paramName) => {
route = route.replace(req.params[paramName], ':' + paramName);
});
}

// this condition will evaluate to true only in
// express framework and no route was found for the request. if we log this metrics
// we'll risk in a memory leak since the route is not a pattern but a hardcoded string.
Expand Down
21 changes: 21 additions & 0 deletions test/integration-tests/nest-js/middleware-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ describe('when using nest-js framework', () => {
});
});
});

describe('route should be unaltered by user inputs (#114)', () => {
before(() => {
return request(server)
.get('/users/s/app-id/p')
.expect(200)
.expect({
app_id: 'some_app_id'
});
});

it('should add it to the histogram', () => {
return request(server)
.get('/metrics')
.expect(200)
.then((res) => {
expect(res.text).to.contain('method="GET",route="/users/:user_id/app-id/:app_id",code="200"');
});
});
});

describe('When calling a GET user/:user_id/app-id/:app_id with user_id and app_id as pattern and query params', () => {
before(() => {
return request(server)
Expand Down