X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=examples%2Ftypescript%2Fhttp-server-pool%2Fexpress-hybrid%2Fsrc%2Fexpress-worker.ts;h=7ba9f374f5fa248012fab50afb72e508f8391de4;hb=d44859e71950912c8de6e9028592c833dde3e86b;hp=db05cdbeb0cc745bfe77b33ee200dc1d4d2ba835;hpb=563b18cd8fe9c211f15e9da91a299f2819abea01;p=poolifier.git diff --git a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts index db05cdbe..7ba9f374 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts @@ -1,11 +1,13 @@ -import type { Server } from 'http' -import type { AddressInfo } from 'net' +import type { Server } from 'node:http' +import type { AddressInfo } from 'node:net' + +import express, { type Express, type Request, type Response } from 'express' import { + availableParallelism, ClusterWorker, - DynamicThreadPool, - availableParallelism + DynamicThreadPool } from 'poolifier' -import express, { type Express, type Request, type Response } from 'express' + import { type ClusterWorkerData, type ClusterWorkerResponse, @@ -32,7 +34,7 @@ ClusterWorkerResponse workerData?: ClusterWorkerData ): ClusterWorkerResponse => { const { port, workerFile, minWorkers, maxWorkers, ...poolOptions } = - workerData as ClusterWorkerData + workerData! ExpressWorker.requestHandlerPool = new DynamicThreadPool< ThreadWorkerData, @@ -68,15 +70,16 @@ ClusterWorkerResponse .catch(emptyFunction) }) + let listenerPort: number | undefined ExpressWorker.server = application.listen(port, () => { + listenerPort = (ExpressWorker.server.address() as AddressInfo).port console.info( - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `⚡️[express server]: Express server is started in cluster worker at http://localhost:${port}/` + `⚡️[express server]: Express server is started in cluster worker at http://localhost:${listenerPort}/` ) }) return { status: true, - port: (ExpressWorker.server.address() as AddressInfo)?.port ?? port + port: listenerPort ?? port } }