1 import { type RawData
, WebSocketServer
} from
'ws'
2 import { type DataPayload
, type MessagePayload
, MessageType
} from
'./types.js'
3 import { requestHandlerPool
} from
'./pool.js'
6 const wss
= new WebSocketServer({ port
}, () => {
8 `⚡️[ws server]: WebSocket server is started at ws://localhost:${port}/`
12 const emptyFunction
= (): void => {
16 wss
.on('connection', (ws
) => {
17 ws
.on('error', console
.error
)
18 ws
.on('message', (message
: RawData
) => {
19 const { type, data
} = JSON
.parse(
20 // eslint-disable-next-line @typescript-eslint/no-base-to-string
22 ) as MessagePayload
<DataPayload
>
24 case MessageType
.echo
:
26 .execute({ data
}, 'echo')
30 type: MessageType
.echo
,
38 case MessageType
.factorial
:
40 .execute({ data
}, 'factorial')
44 type: MessageType
.factorial
,