Skip to content

[node-ws] "injectWebSocket" drops the env parameter for app.fetch #1732

@PeterZhenhh

Description

@PeterZhenhh

Which middleware has the bug?

@hono/node-ws

What version of the middleware?

1.3.0

What version of Hono are you using?

4.11.4

What runtime/platform is your app running on? (with version if possible)

Node.js 22.19.0

What steps can reproduce the bug?

Server:

// index.js
import { createNodeWebSocket } from '@hono/node-ws'
import { serve } from '@hono/node-server'
import app from './base.js'

const { injectWebSocket } = createNodeWebSocket({ app })
const server = serve({
    port: 8080,
    fetch: async (request) => {
        let env = {
            customEnv: '1'
        }
        return app.fetch(request, env)
    }
}, (info) => {
    console.log(
        `Server listening on http://${info.address}:${info.port}`
    )
})
injectWebSocket(server)
// base.js
import { Hono } from 'hono'

const app = new Hono()
app.all("*", async (c) => {
  console.log(c.env.customEnv); // undefined, should be '1'
  return c.text("OK")
})

export default app

Client:

new WebSocket("ws://127.0.0.1:8080")

What is the expected behavior?

console.log(c.env.customEnv) should be '1'

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions