private static readonly startFastify = async (
workerData?: ClusterWorkerData
): Promise<ClusterWorkerResponse> => {
- 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<{
}>('/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()
+ }
+ })
}
}