Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/express-worker_thr...
[poolifier.git] / examples / typescript / http-server-pool / fastify-hybrid / src / fastify-worker.ts
index 89fc333872ef1fea7603ec58290af8e191f10d49..9c2cb3c52d57e95f5452e624a0bde9ffd4e1a4ed 100644 (file)
@@ -14,6 +14,7 @@ ClusterWorkerResponse
     workerData?: ClusterWorkerData
   ): Promise<ClusterWorkerResponse> => {
     const { port } = workerData as ClusterWorkerData
+
     FastifyWorker.fastify = Fastify({
       logger: true
     })
@@ -22,8 +23,8 @@ ClusterWorkerResponse
 
     FastifyWorker.fastify.all('/api/echo', async (request) => {
       return (
-        await FastifyWorker.fastify.execute({ body: request.body }, 'echo')
-      ).body
+        await FastifyWorker.fastify.execute({ data: request.body }, 'echo')
+      ).data
     })
 
     FastifyWorker.fastify.get<{
@@ -31,8 +32,8 @@ ClusterWorkerResponse
     }>('/api/factorial/:number', async (request) => {
       const { number } = request.params
       return (
-        await FastifyWorker.fastify.execute({ body: { number } }, 'factorial')
-      ).body
+        await FastifyWorker.fastify.execute({ data: { number } }, 'factorial')
+      ).data
     })
 
     await FastifyWorker.fastify.listen({ port })
@@ -43,7 +44,12 @@ ClusterWorkerResponse
   }
 
   public constructor () {
-    super(FastifyWorker.startFastify)
+    super(FastifyWorker.startFastify, {
+      killHandler: async () => {
+        await FastifyWorker.fastify.pool.destroy()
+        await FastifyWorker.fastify.close()
+      }
+    })
   }
 }