X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Ffastify-hybrid%2Fsrc%2Ffastify-worker.ts;h=0566ee014dd75e8520f93ee154f304018707f70d;hb=1fa0cdf5c1471f14c09c7a33131f14f13215996b;hp=89fc333872ef1fea7603ec58290af8e191f10d49;hpb=8ad621cc1d32ed396fca3ef2ec48337e42d2dcc2;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 89fc3338..0566ee01 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,17 +13,21 @@ ClusterWorkerResponse private static readonly startFastify = async ( workerData?: ClusterWorkerData ): Promise => { - const { port } = workerData as ClusterWorkerData + const { port, ...fastifyPoolifierOptions } = workerData as ClusterWorkerData + FastifyWorker.fastify = Fastify({ logger: true }) - await FastifyWorker.fastify.register(fastifyPoolifier, workerData) + await FastifyWorker.fastify.register( + fastifyPoolifier, + fastifyPoolifierOptions + ) 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,19 +35,24 @@ 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 }) 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.pool.destroy() + await FastifyWorker.fastify.close() + } + }) } }