Skip to content

Commit

Permalink
feat: switch to fastify v5
Browse files Browse the repository at this point in the history
Migrate plugin to fastify 5

BREAKING CHANGE: fastify 4 is not supported anymore and minumum required Node.js version is 20.
  • Loading branch information
dnlup committed Nov 29, 2024
1 parent 1ac576b commit 8a73762
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node-version: [18.x, 20.x]
node-version: [20.x, 22.x]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ module.exports = fp(
},
{
name: '@immobiliarelabs/fastify-metrics',
fastify: '>=4.x',
fastify: '^5.0.0',
}
);
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { FastifyRouteConfig } from 'fastify/types/route';

function getFastify(options?: MetricsPluginOptions) {
const instance = Fastify();
return instance.register(plugin, options);
return instance.register(plugin, options || {});
}

expectType<FastifyPluginCallback<MetricsPluginOptions>>(plugin);
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.onRequest = function (request, reply, next) {
};

exports.onResponse = function (request, reply, next) {
reply.sendTimingMetric('response_time', reply.getResponseTime());
reply.sendTimingMetric('response_time', reply.elapsedTime);
next();
};

Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"license": "MIT",
"engines": {
"node": ">=18"
"node": ">=20"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
Expand All @@ -66,7 +66,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0-alpha.2",
"fastify": "^4.25.1",
"fastify": "^5.1.0",
"husky": "^8.0.0",
"is-ci": "^3.0.0",
"lint-staged": "^15.2.0",
Expand All @@ -81,10 +81,9 @@
"@dnlup/doc": "^5.0.3",
"@dnlup/hrtime-utils": "^1.0.1",
"@immobiliarelabs/dats": "^5.1.0",
"fastify-plugin": "^4.0.0"
"fastify-plugin": "^5.0.1"
},
"volta": {
"node": "18.15.0",
"npm": "9.6.2"
"node": "20.18.1"
}
}

0 comments on commit 8a73762

Please sign in to comment.