-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@hono/vite-dev-server] add bun websocket support #140
Comments
+1 on this. As a workaround I did this: (Separating 3000 backend and 3001 for ws) But encountered this: (Two instances of It works fine on prod tho. Just dev that kinda sucks for devx. |
To add more to the discussion. Here's a video to demonstrate that visually. I was thinking I could just change the HMR port so it doesn't conflict with each other inside hono.dev.server.websockets.bug.mp4Have not tested on Node yet. But will try if I can when I get time. |
Hmmmm. I've reconsidered this issue. However, the WebSocket matter is tricky for the Vite dev-server. We can trust Bun: import { Hono } from 'hono'
import { createBunWebSocket } from 'hono/bun'
const { upgradeWebSocket, websocket } = createBunWebSocket()
// ...
Bun.serve({
fetch: app.fetch,
websocket,
}) Node.js: import { createNodeWebSocket } from '@hono/node-ws'
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
const app = new Hono()
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app })
app.get('/ws', upgradeWebSocket((c) => ({
// https://hono.dev/helpers/websocket
})))
const server = serve(app)
injectWebSocket(server) To enable supporting both, we may add the option for choosing the current running runtime of Vite like the following: import devServer from '@hono/vite-dev-server'
import { defineConfig } from 'vite'
import { runtime } from '@hono/vite-dev-server/bun'
export default defineConfig({
plugins: [
devServer({
runtime
})
]
}) I think this is relevant to Vite's new environment API: vitejs/vite#16358 Perhaps we can use a different runtime in Vite, like Node.js or worked (or Bun?). So, the better way is not to hurry up and follow the Vite's action though we have to figure out a workaround. |
dev server does not run websocket:
desired behaviour: should connect to websocket server when
new WebSocket("ws://localhost:5173/ws")
is calledcurrent behaviour: fetch requests work fine, websocket request hangs
The text was updated successfully, but these errors were encountered: