X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Ffastify-hybrid%2Fsrc%2Ffastify-worker.ts;h=0f4f6370b4c5249a2dfc8f2b4169d0245bbdda68;hb=6bca4154b0b57b8e4b0885a52a77cc8a70dccb88;hp=7a09a1ce38666ea1a0ad45e056adb4a1f89f8034;hpb=ff6cf64964e78aafa95098852ec0472b567f7b1b;p=poolifier.git diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts index 7a09a1ce..0f4f6370 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts @@ -13,26 +13,30 @@ ClusterWorkerResponse private static readonly startFastify = async ( workerData?: ClusterWorkerData ): Promise => { - const { port } = workerData as ClusterWorkerData + const { port, ...fastifyPoolifierOptions } = workerData! + FastifyWorker.fastify = Fastify({ logger: true }) - await FastifyWorker.fastify.register(fastifyPoolifier, workerData) + await FastifyWorker.fastify.register( + fastifyPoolifier, + fastifyPoolifierOptions + ) - 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 }) @@ -45,6 +49,7 @@ ClusterWorkerResponse public constructor () { super(FastifyWorker.startFastify, { killHandler: async () => { + await FastifyWorker.fastify.pool.destroy() await FastifyWorker.fastify.close() } })