https://github.com/blankeos/express-vike-websockets
Repro to demonstrate that Vite + Express Custom Server supports websockets.
https://github.com/blankeos/express-vike-websockets
Last synced: about 1 year ago
JSON representation
Repro to demonstrate that Vite + Express Custom Server supports websockets.
- Host: GitHub
- URL: https://github.com/blankeos/express-vike-websockets
- Owner: Blankeos
- Created: 2024-06-26T20:32:01.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T23:29:45.000Z (almost 2 years ago)
- Last Synced: 2025-02-13T08:41:20.479Z (over 1 year ago)
- Language: TypeScript
- Size: 310 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express, Vike, and Websockets
### Checklist to know it works:
- [x] The HMR works when you edit `+Page.tsx`
- [x] The WebSocket handler works when you make a request to it.

To test the websocket. Just go to the browser console with the app opened and paste this:
```ts
const socket = new WebSocket('ws://localhost:3000/ws');
// Event handler for when the connection is established
socket.onopen = function(event) {
console.log("OPEN");
socket.send('WebSocket is open now.');
};
// Event handler for when a message is received from the server
socket.onmessage = function(event) {
console.log('Message from server:', event.data);
};
// Event handler for when the connection is closed
socket.onclose = function(event) {
console.log('WebSocket is closed now.');
};
// Event handler for when an error occurs
socket.onerror = function(error) {
console.log('WebSocket error:', error);
};
```
This app as scaffolded using [Bati](https://batijs.dev/)
```ts
pnpm create @batijs/app --react --express
```