Skip to content

hono vite dev server doesn't allow websockets to connect #253

@benjamine

Description

@benjamine

I followed the guide at https://hono.dev/docs/getting-started/cloudflare-pages
and then added websockets following https://hono.dev/docs/helpers/websocket
see repo here: https://github.com/benjamine/hono-vite-websocket (made to reproduce this)

websocket never connects when running the vite dev server (I think because there's never a server upgrade).

websocket works correclty when using vite build+preview or when deployed to cloudflare.

reproduction steps:

  • clone the repo
  • npm i && npm run dev
  • check the console or network tab, note that the browser's websocket never connects

I noticed connection succeeds adding an upgrade handler at the vite plugin

	configureServer(server) {
                ...
		server.httpServer?.on("upgrade", (request, socket, head) => {
                     ...
                     // handle this similarly to hono-node/ws ?

and confirmed that makes the connecting succeed (but this might not be the right way or place to handle it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions