import type { AddressInfo } from 'node:net'
-import { ClusterWorker } from 'poolifier'
+
import Fastify, { type FastifyInstance } from 'fastify'
-import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
+import { ClusterWorker } from 'poolifier'
+
import { fastifyPoolifier } from './fastify-poolifier.js'
+import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js'
class FastifyWorker extends ClusterWorker<
-ClusterWorkerData,
-ClusterWorkerResponse
+ ClusterWorkerData,
+ ClusterWorkerResponse
> {
private static fastify: FastifyInstance
private static readonly startFastify = async (
workerData?: ClusterWorkerData
): Promise<ClusterWorkerResponse> => {
- const { port, ...fastifyPoolifierOptions } = workerData as ClusterWorkerData
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const { port, ...fastifyPoolifierOptions } = workerData!
FastifyWorker.fastify = Fastify({
- logger: true
+ logger: true,
})
await FastifyWorker.fastify.register(
await FastifyWorker.fastify.listen({ port })
return {
status: true,
- port: (FastifyWorker.fastify.server.address() as AddressInfo)?.port
+ port: (FastifyWorker.fastify.server.address() as AddressInfo).port,
}
}
killHandler: async () => {
await FastifyWorker.fastify.pool.destroy()
await FastifyWorker.fastify.close()
- }
+ },
})
}
}