X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=examples%2Ftypescript%2Fhttp-server-pool%2Fexpress-cluster%2Fsrc%2Fworker.ts;h=7dd607b5b17cfd703d4dd75ae0c08d5aa6c5dd7b;hb=b9917020a4b251d00946b9174fc9d05299ab13db;hp=27eda6f4d5f810442e8a4c3a083dfc56531da2e3;hpb=15a9c19523fb6e13e034776b45121d6af1b1209e;p=poolifier.git diff --git a/examples/typescript/http-server-pool/express-cluster/src/worker.ts b/examples/typescript/http-server-pool/express-cluster/src/worker.ts index 27eda6f4..7dd607b5 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/worker.ts @@ -1,10 +1,10 @@ -import type { Server } from 'http' -import type { AddressInfo } from 'net' +import type { Server } from 'node:http' +import type { AddressInfo } from 'node:net' import { ClusterWorker } from 'poolifier' import express, { type Express, type Request, type Response } from 'express' -import { type WorkerData, type WorkerResponse } from './types.js' +import type { WorkerData, WorkerResponse } from './types.js' -const factorial: (n: number) => number = (n) => { +const factorial: (n: number) => number = n => { if (n === 0) { return 1 } @@ -17,6 +17,8 @@ class ExpressWorker extends ClusterWorker { private static readonly startExpress = ( workerData?: WorkerData ): WorkerResponse => { + const { port } = workerData as WorkerData + const application: Express = express() // Parse only JSON requests body @@ -31,17 +33,15 @@ class ExpressWorker extends ClusterWorker { res.send({ number: factorial(parseInt(number)) }).end() }) - ExpressWorker.server = application.listen(workerData?.port, () => { + ExpressWorker.server = application.listen(port, () => { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `⚡️[express server]: Express server is started in cluster worker at http://localhost:${workerData?.port}/` + `⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/` ) }) return { status: true, - port: - (ExpressWorker.server.address() as AddressInfo)?.port ?? - workerData?.port + port: (ExpressWorker.server.address() as AddressInfo)?.port ?? port } }