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 dd77f1238a90a203185f1fe2a9ae4b803d378e5f..9c2cb3c52d57e95f5452e624a0bde9ffd4e1a4ed 100644 (file)
@@ -14,25 +14,26 @@ ClusterWorkerResponse
     workerData?: ClusterWorkerData
   ): Promise<ClusterWorkerResponse> => {
     const { port } = workerData as ClusterWorkerData
+
     FastifyWorker.fastify = Fastify({
       logger: true
     })
 
     await FastifyWorker.fastify.register(fastifyPoolifier, workerData)
 
-    FastifyWorker.fastify.all('/api/echo', async request => {
+    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<{
       Params: { number: number }
-    }>('/api/factorial/:number', async request => {
+    }>('/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()
+      }
+    })
   }
 }