nitrojs / nitrojs/nitro

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

Open
#4,547 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug v3
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Elysia app inside Nitro with the shown websocket configuration and client. Trace Nitro's websocket handling and the Elysia integration to find why the successful handshake does not invoke the registered /ws handler. Done means the handler runs after connection and the client receives 1, 2, and 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.