Welcome to the Linux Foundation Forum!

Cannot get the WebSockets example working

cfinis
cfinis Posts: 1
edited June 2024 in LFW111 Class Forum

Hello,
I'm running the LFW111 course examples on node 20.11.0 with

  "dependencies": {
    "@fastify/autoload": "^5.0.0",
    "@fastify/cors": "^9.0.1",
    "@fastify/sensible": "^5.0.0",
    "@fastify/websocket": "^10.0.1",
    "fastify": "^4.26.1",
    "fastify-cli": "^6.2.1",
    "fastify-plugin": "^4.0.0"
  },

The Web Sockets example in lesson 04 (Going Realtime) doesn't work for me. When I run the mock-service, and select a category in the static web page, the mock service of the routes/orders plugin throws an error complaining that the socket is undefined:

[16:45:38.506] ERROR (369197): Cannot read properties of undefined (reading 'send')
    reqId: "req-2"
    err: {
      "type": "TypeError",
      "message": "Cannot read properties of undefined (reading 'send')",
      "stack":
          TypeError: Cannot read properties of undefined (reading 'send')
              at Object.<anonymous> (file:///home/cfinis/workspace/jsnad/my-project-WS/mock-srv/routes/orders/index.mjs:9:16)
              at /home/cfinis/workspace/jsnad/my-project-WS/mock-srv/node_modules/@fastify/websocket/index.js:185:34
...
}

Any idea what is going wrong?

Thanks

Answers

Categories

Upcoming Training