Skip to content

WebSocket connection succeeds but Elysia WebSocket handler is not triggered when running inside Nitro #4547

Description

@kangkangovo12138

Environment

node

Reproduction

I am using Elysia as a handler inside Nitro. I enabled WebSocket support in Elysia and the WebSocket connection can be established successfully, but the Elysia WebSocket handler is never executed.

Environment

  • Nitro version:
  • Elysia version:
  • Runtime: Bun
  • OS:

Reproduction

Elysia app:

import { Elysia } from 'elysia'
import { websocket } from 'elysia/websocket'

export const app = new Elysia()
  .use(websocket())
  .ws('/ws', function* () {
    console.log('handler entered')

    yield 1
    yield 2
    yield 3
  })

Nitro config:

export default defineNitroConfig({
  features: {
    websocket: true
  }
})

Client:

const ws = new WebSocket('ws://localhost:3000/ws')

ws.onopen = () => {
  console.log('connected')
}

ws.onmessage = (event) => {
  console.log(event.data)
}

Expected behavior

After the WebSocket connection is established, the Elysia WebSocket handler should be executed:

connected
handler entered
1
2
3

Actual behavior

The WebSocket handshake succeeds:

WebSocket connection established

but the Elysia handler is never entered:

(no console output)

No error is thrown.

Describe the bug

none

Additional context

No response

Logs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions