Skip to content

Commit

Permalink
feat: support onListen hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Sep 14, 2023
1 parent 1d09bc1 commit 99b918c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ The JSON structure returned by the `overview` method is like the following:
"onSend": [],
"onResponse": [],
"onTimeout": [],
"onListen": [],
"onReady": [],
"onClose": [],
"onRoute": [],
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface OverviewStructureHooks {
onSend?: OverviewStructureHook[],
onResponse?: OverviewStructureHook[],
onTimeout?: OverviewStructureHook[],
onListen?: OverviewStructureHook[],
onReady?: OverviewStructureHook[],
preClose?: OverviewStructureHook[],
onClose?: OverviewStructureHook[],
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function getJsonOverview (request, reply) {

const plugin = fp(fastifyOverview, {
name: 'fastify-overview',
fastify: '^4.x'
fastify: '^4.23.x'
})

module.exports = plugin
Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function getEmptyHookRoute () {

function getEmptyHookApplication () {
return {
onListen: [],
onReady: [],
preClose: [],
onClose: [],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.0.0",
"fastify": "^4.0.2",
"fastify": "^4.23.0",
"standard": "^17.0.0",
"tap": "^16.0.1",
"tsd": "^0.29.0"
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/app-no-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -158,6 +159,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -204,6 +206,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -315,6 +318,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/app-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -258,6 +259,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -324,6 +326,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -525,6 +528,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down
9 changes: 9 additions & 0 deletions test/fixture/autoload.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -292,6 +293,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -358,6 +360,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -424,6 +427,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -490,6 +494,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -646,6 +651,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -763,6 +769,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -829,6 +836,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down Expand Up @@ -1030,6 +1038,7 @@
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down
6 changes: 6 additions & 0 deletions test/fixture/index.00.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"hash": "97eb877315c76c90eccaf8fe6fb2015477bbf401"
}
],
"onListen": [
{
"name": "onListen",
"hash": "9294d9abb602193c9b3cd02624da004b4b9e0da1"
}
],
"onReady": [],
"preClose": [],
"onClose": [],
Expand Down
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('basic test', async t => {
app.addHook('onResponse', async function hook8 () {})
app.addHook('onTimeout', () => {})
app.addHook('onRequestAbort', async function hookAbort (request) { })
app.addHook('onListen', async function onListen () { })

app.register(function (instance, opts, next) { next() })
app.register(async function (instance, opts) { })
Expand Down

0 comments on commit 99b918c

Please sign in to comment.