Skip to content
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

websockets in hook not working #53

Open
vyconm opened this issue Apr 2, 2024 · 3 comments
Open

websockets in hook not working #53

vyconm opened this issue Apr 2, 2024 · 3 comments

Comments

@vyconm
Copy link

vyconm commented Apr 2, 2024

No matter if client-side or server-side, if I open a new websocket, it does not pass through the handle hook.
More documentation on the websockets implementation would be helpful, as the bun documentation only partially extends this documentation.

Using the exact code from the example in the readme, in dev, preview and build. e.g.:
const ws = new WebSocket(
wsURL
);

@dukedorje
Copy link

I ran across the same thing. Diving into the code, there's a hack at the button of /index.js which rewrites handleWebsocket to be this.websocket = -- but I can't find where it's creating the Bun websocket etc.

Try building for production (bun run build, bun run build/index.js) then connect to Websocket on the default port 3000. (has to be /ws by default : ( if (url.pathname.startsWith('/ws')) { )

From other sources on the web, for this to work in development mode we'll need to create a Vite plugin. Not sure how to do that yet.

(Also changing output directory is useful since bun will help since bun will refuse to run the script in package.json if build/index.js exists.)

@dukedorje
Copy link

I tried like hell to get a self-contained vite plugin working. But finally gave up and used the code in examples/e2e

It uses vite's proxy function, and runs a dedicated Bun process just for websockets.

I think we could change the vite DevServer to use bun for everything. But that's more than I want to bite off right now.

@dukedorje
Copy link

#25 Might be helpful too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants