Skip to content

Websockets ws.data returns undefined with node adapter #50

@ShiromiTsukasa

Description

@ShiromiTsukasa

What version of Elysia is running?

1.4.13

What version of Node Adapter are you using?

1.4.1

What platform is your computer?

Linux 6.17.4-arch2-1 x86_64 unknown

What steps can reproduce the bug?

  1. Copy the following program into a new project's index.ts
import node from "@elysiajs/node";
import { Elysia } from "elysia";

const app = new Elysia({
  adapter: node()
})
  .ws("/ws", {
    open(ws) { console.log(ws.data); }
  }).listen(3000, ({hostname, port}) => {
    console.log(`Elysia running at ${hostname}:${port}`);
  });
  1. Run with npm run dev (this should be tsx watch src/index.ts for node project)
  2. Open a websocket connection to the application (e.g. through Postman)
  3. Observe

What is the expected behavior?

The bun version's output

pwsh> bun run dev
$ bun --watch src/index.ts
Elysia is running at localhost:3000
{
  request: Request (0 KB) {
    method: "GET",
    url: "http://localhost:3000/ws",
    headers: Headers {
      "sec-websocket-version": "13",
      "sec-websocket-key": "XXp4h6PtTrfX0A+ZeWHkhw==",
      "connection": "Upgrade",
      "upgrade": "websocket",
      "sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
      "host": "localhost:3000",
    }
  },
  store: {},
  qi: -1,
  path: "/ws",
  url: "http://localhost:3000/ws",
  redirect: [Function: redirect],
  status: [Function: status],
  set: {
    headers: [Object: null prototype] {},
    status: 200,
    cookie: {},
  },
  headers: {
    "sec-websocket-version": "13",
    "sec-websocket-key": "XXp4h6PtTrfX0A+ZeWHkhw==",
    connection: "Upgrade",
    upgrade: "websocket",
    "sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
    host: "localhost:3000",
  },
  cookie: {},
  query: [Object: null prototype] {},
  route: "/ws",
  validator: undefined,
  id: [Getter],
  ping: [Function: ping],
  pong: [Function: pong],
  open: [AsyncFunction: open],
  message: [AsyncFunction: message],
  drain: [AsyncFunction: drain],
  close: [AsyncFunction: close],
}

What do you see instead?

pwsh> npm run dev

> dev
> tsx watch src/index.ts

Elysia running at localhost:3000
undefined

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions