Merge branch 'master' into combined-prs-branch
[poolifier.git] / examples / typescript / websocket-server-pool / ws-worker_threads / src / main.ts
index d5b2cc78e8e4feda873602ea9b1074e581d3d8f9..cb28beebb18b9eaa4579b7630ef0a23bc8ceadfb 100644 (file)
@@ -1,11 +1,12 @@
 import { type RawData, WebSocketServer } from 'ws'
-import { type DataPayload, type MessagePayload, MessageType } from './types.js'
+
 import { requestHandlerPool } from './pool.js'
+import { type DataPayload, type MessagePayload, MessageType } from './types.js'
 
 const port = 8080
 const wss = new WebSocketServer({ port }, () => {
   console.info(
-    `⚡️[ws server]: WebSocket server is started at ws://localhost:${port}/`
+    `⚡️[ws server]: WebSocket server is started at ws://localhost:${port.toString()}/`
   )
 })
 
@@ -28,7 +29,7 @@ wss.on('connection', ws => {
             ws.send(
               JSON.stringify({
                 type: MessageType.echo,
-                data: response.data
+                data: response.data,
               })
             )
             return undefined
@@ -40,10 +41,13 @@ wss.on('connection', ws => {
           .execute({ data }, 'factorial')
           .then(response => {
             ws.send(
-              JSON.stringify({
-                type: MessageType.factorial,
-                data: response.data
-              })
+              JSON.stringify(
+                {
+                  type: MessageType.factorial,
+                  data: response.data,
+                },
+                (_, v: unknown) => (typeof v === 'bigint' ? v.toString() : v)
+              )
             )
             return undefined
           })