Skip to content

WebSocket doesn't work #4976

Description

@Migawk

What version of Hono are you using?

4.12.23

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

Bun

What steps can reproduce the bug?

Prereq: WSL Ubuntu 24.04, Bun 1.3.14
Init basic Hono project with cors ( * everywhere ) and simplest websocket gateway taken from docs.

import { Hono } from "hono";
import { upgradeWebSocket, websocket } from "hono/bun";
import { cors } from "hono/cors";

const app = new Hono();

app.use(
  "*",
  cors({
    origin: "*",
    allowHeaders: ["*"],
    allowMethods: ["POST", "GET", "OPTIONS"],
    exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
    maxAge: 600,
    credentials: true,
  }),
);

app.get(
  "/ws",
  upgradeWebSocket((c) => {
    return {
      onMessage(event, ws) {
        console.log(`Message from client: ${event.data}`);
        ws.send("Hello from server!");
      },
      onClose: () => {
        console.log("Connection closed");
      },
    };
  }),
);

export default {
  fetch: app.fetch,
  websocket,
};

What is the expected behavior?

Working Websocket gateway.

What do you see instead?

Not working gateway

Additional information

I've set console.log into helper/websocket/index.js and it works when a user makes GET request, but still getting 404 on my client.

Tested with Express.js. Everything working as awaited

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