-const startFastify = async (
- workerData?: WorkerData
-): Promise<WorkerResponse> => {
- const { port } = workerData as WorkerData
- const fastify = Fastify({
- logger: true
- })
-
- fastify.all('/api/echo', request => {
- return request.body
- })
-
- fastify.get<{
- Params: { number: number }
- }>('/api/factorial/:number', request => {
- const { number } = request.params
- return { number: factorial(number) }
- })
-
- await fastify.listen({ port })
- return {
- status: true,
- port: (fastify.server.address() as AddressInfo).port
+ private static readonly startFastify = async (
+ workerData?: WorkerData
+ ): Promise<WorkerResponse> => {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const { port } = workerData!
+
+ FastifyWorker.fastify = Fastify({
+ logger: true,
+ })
+
+ FastifyWorker.fastify.all('/api/echo', request => {
+ return request.body
+ })
+
+ FastifyWorker.fastify.get<{
+ Params: { number: number }
+ }>('/api/factorial/:number', request => {
+ const { number } = request.params
+ return { number: FastifyWorker.factorial(number).toString() }
+ })
+
+ await FastifyWorker.fastify.listen({ port })
+ return {
+ status: true,
+ port: (FastifyWorker.fastify.server.address() as AddressInfo).port,
+ }