build(deps-dev): bump typescript
[poolifier.git] / examples / typescript / http-server-pool / fastify-cluster / src / worker.ts
index 3f7b3661f99cd2f51082366eadfc8cbe17ba804a..283a223e3438aa07af36343368d6dd03de05017e 100644 (file)
@@ -17,6 +17,7 @@ class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
     workerData?: WorkerData
   ): Promise<WorkerResponse> => {
     const { port } = workerData as WorkerData
+
     FastifyWorker.fastify = Fastify({
       logger: true
     })
@@ -35,12 +36,16 @@ class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
     await FastifyWorker.fastify.listen({ port })
     return {
       status: true,
-      port: (FastifyWorker.fastify.server.address() as AddressInfo).port
+      port: (FastifyWorker.fastify.server.address() as AddressInfo)?.port
     }
   }
 
   public constructor () {
-    super(FastifyWorker.startFastify)
+    super(FastifyWorker.startFastify, {
+      killHandler: async () => {
+        await FastifyWorker.fastify.close()
+      }
+    })
   }
 }