fix: fix possible null property exception in examples
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 16 Aug 2023 15:38:54 +0000 (17:38 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 16 Aug 2023 15:38:54 +0000 (17:38 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts
examples/typescript/http-server-pool/fastify-cluster/src/worker.ts
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts

index 56fad6d1b9edec47d79dd4e283dfe638e9507dfd..901c207244be4a9783521d808da25b4f59f594bd 100644 (file)
@@ -71,14 +71,12 @@ ClusterWorkerResponse
     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
     }
   }
 
index d70b76dd7f93f2d026126ef7b84b46504f2361bd..283a223e3438aa07af36343368d6dd03de05017e 100644 (file)
@@ -36,7 +36,7 @@ class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
     await FastifyWorker.fastify.listen({ port })
     return {
       status: true,
-      port: (FastifyWorker.fastify.server.address() as AddressInfo).port
+      port: (FastifyWorker.fastify.server.address() as AddressInfo)?.port
     }
   }
 
index e21eb58c01294014fd9557f067c6544bcfcca18a..0566ee014dd75e8520f93ee154f304018707f70d 100644 (file)
@@ -42,7 +42,7 @@ ClusterWorkerResponse
     await FastifyWorker.fastify.listen({ port })
     return {
       status: true,
-      port: (FastifyWorker.fastify.server.address() as AddressInfo).port
+      port: (FastifyWorker.fastify.server.address() as AddressInfo)?.port
     }
   }