Skip to content

Commit

Permalink
fix(deprecation): prefer request.routeOptions.method over request.rou…
Browse files Browse the repository at this point in the history
…terMethod (#93)
  • Loading branch information
juleswritescode authored Oct 31, 2023
1 parent b2a8fc2 commit f8d5ed3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Feel free to contribute to this project.

- Use `pnpm` to manage deps.
- Make sure that all your changes fit codestyle, run `pnpm run lint`.
- Make sure that all your changes have tests, run `pnpm run unit`.
- Make sure that all your changes have tests, run `pnpm run test:unit`.
- Make sure that all your changes have documented in [README](README.md).
- Make sure that all your commits follow conventional commit [guide](https://conventionalcommits.org/).
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ This plugin also adds two http metrics for your routes:
### v10.x.x

- Replace route `context.config` with `routeConfig` due to deprecation in fastify v4 and removal in fastify v5. If you had `disableMetrics` option in you route `config`, update fastify to latest version.
- Prefer `request.routeOptions.method` over deprecated `request.routerMethod`.

### v9.x.x

Expand Down
6 changes: 5 additions & 1 deletion src/fastify-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ export class FastifyMetrics implements IFastifyMetrics {

if (this.options.routeMetrics.registeredRoutesOnly === false) {
if (
!this.methodBlacklist.has(request.routerMethod ?? request.method)
!this.methodBlacklist.has(
request.routeOptions?.method ??
request.routerMethod ??
request.method
)
) {
this.metricStorage.set(request, {
hist: this.routeMetrics.routeHist.startTimer(),
Expand Down

0 comments on commit f8d5ed3

Please sign in to comment.