From b7172bc04e803e849ba215e368cb32e788febcb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 30 Mar 2024 21:34:39 +0100 Subject: [PATCH] fix(examples): fix express cluster worker error at startup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../http-server-pool/express-cluster/src/worker.ts | 6 ++++-- .../http-server-pool/express-hybrid/src/express-worker.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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 da2e9ad7..98ca45de 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/worker.ts @@ -43,14 +43,16 @@ class ExpressWorker extends ClusterWorker { .end() }) + let listenerPort: number | undefined ExpressWorker.server = application.listen(port, () => { + listenerPort = (ExpressWorker.server.address() as AddressInfo).port console.info( - `⚡️[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: listenerPort ?? port } } 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 78a18d67..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 @@ -70,14 +70,16 @@ ClusterWorkerResponse .catch(emptyFunction) }) + let listenerPort: number | undefined ExpressWorker.server = application.listen(port, () => { + listenerPort = (ExpressWorker.server.address() as AddressInfo).port console.info( - `⚡️[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: listenerPort ?? port } } -- 2.34.1