X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Ffastify-hybrid%2Fsrc%2Ffastify-worker.ts;h=388730dcec9bda04a13315f4f0b5fb1814981266;hb=852b1334a4cf0b0446603a0f1d817c3f4afbfa07;hp=89fc333872ef1fea7603ec58290af8e191f10d49;hpb=de2e7182cca6b34b000a09bf6d0ddcff4757db3a;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..388730dc 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,37 +13,46 @@ 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) => { + 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 }) 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() + } + }) } }