From 83c9ca26edc39be216ab263a57a4933eccb79c22 Mon Sep 17 00:00:00 2001 From: Jean <110341611+jean-michelet@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:29:03 +0200 Subject: [PATCH] refactor: uninstall global listeners not needed on eject templates (#732) --- README.md | 7 +------ templates/eject-esm/server.js | 7 +------ templates/eject-ts/server.ts | 7 +------ templates/eject/server.js | 7 +------ 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index df8575a9..1e588b26 100644 --- a/README.md +++ b/README.md @@ -218,18 +218,13 @@ const appService = require('./app.js') app.register(appService) // delay is the number of milliseconds for the graceful close to finish -const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { +closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { if (err) { app.log.error(err) } await app.close() }) -app.addHook('onClose', (instance, done) => { - closeListeners.uninstall() - done() -}) - // Start listening. app.listen({ port: process.env.PORT || 3000 }, (err) => { if (err) { diff --git a/templates/eject-esm/server.js b/templates/eject-esm/server.js index 42c4ae9e..3001fa62 100644 --- a/templates/eject-esm/server.js +++ b/templates/eject-esm/server.js @@ -22,18 +22,13 @@ const app = Fastify({ app.register(appService) // delay is the number of milliseconds for the graceful close to finish -const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { +closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { if (err) { app.log.error(err) } await app.close() }) -app.addHook('onClose', (instance, done) => { - closeListeners.uninstall() - done() -}) - // Start listening. app.listen({ port: process.env.PORT || 3000 }, (err) => { if (err) { diff --git a/templates/eject-ts/server.ts b/templates/eject-ts/server.ts index 802c4de8..d2ea5071 100644 --- a/templates/eject-ts/server.ts +++ b/templates/eject-ts/server.ts @@ -17,18 +17,13 @@ const app = Fastify({ app.register(import("./app")); // delay is the number of milliseconds for the graceful close to finish -const closeListeners = closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) { +closeWithGrace({ delay: parseInt(process.env.FASTIFY_CLOSE_GRACE_DELAY) || 500 }, async function ({ signal, err, manual }) { if (err) { app.log.error(err) } await app.close() } as closeWithGrace.CloseWithGraceAsyncCallback) -app.addHook('onClose', (instance, done) => { - closeListeners.uninstall() - done() -}) - // Start listening. app.listen({ port: parseInt(process.env.PORT) || 3000 }, (err: any) => { if (err) { diff --git a/templates/eject/server.js b/templates/eject/server.js index 66795190..eb96a0e0 100644 --- a/templates/eject/server.js +++ b/templates/eject/server.js @@ -19,18 +19,13 @@ const appService = require('./app.js') app.register(appService) // delay is the number of milliseconds for the graceful close to finish -const closeListeners = closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { +closeWithGrace({ delay: process.env.FASTIFY_CLOSE_GRACE_DELAY || 500 }, async function ({ signal, err, manual }) { if (err) { app.log.error(err) } await app.close() }) -app.addHook('onClose', (instance, done) => { - closeListeners.uninstall() - done() -}) - // Start listening. app.listen({ port: process.env.PORT || 3000 }, (err) => { if (err) {