Skip to content

Commit ae95307

Browse files
committed
feat: Upgrade to uWebSockets.js and implement WebSocket support
- Updated package version to 1.4.0 and changed description in package.json. - Refactored example/index.ts to include WebSocket routes and improved response handling. - Enhanced src/index.ts to support WebSocket connections and message handling. - Introduced UwsWebSocketWrapper class in src/ws.ts for WebSocket management. - Added utility functions in src/utils.ts for creating web requests and applying responses. - Removed deprecated WebSocket handling code and streamlined server setup.
1 parent 4b293c9 commit ae95307

File tree

8 files changed

+604
-416
lines changed

8 files changed

+604
-416
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# 1.4.0 - 27 July 2025
2+
3+
### Added
4+
- Full WebSocket support with publish/subscribe API
5+
- WebSocket lifecycle events (open, message, close)
6+
- `UwsWebSocketWrapper` class for Elysia WebSocket compatibility
7+
8+
### Changed
9+
- **BREAKING**: Upgraded to uWebSockets.js for high performance
10+
- Refactored server architecture for Bun runtime compatibility
11+
- Enhanced streaming request/response handling
12+
13+
### Improved
14+
- Near 1:1 API compatibility with Bun adapter
15+
- Better error handling for WebSocket upgrades
16+
- Streamlined server setup and route registration
17+
18+
### Technical
19+
- Added `createWebRequest` and `applyResponse` utilities
20+
- Integrated with Elysia's WebSocket validation system
21+
- Support for binary/text WebSocket messages
22+
123
# 1.3.0 - 27 May 2025
224
Change:
325
- use WebStandard Compatibility via `@hono/node-server`

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# @elysiajs/node
2-
Adapter for [elysia](https://github.com/elysiajs/elysia) to use Elysia in Nodejs environment.
2+
3+
A high-performance, fully-featured adapter for [Elysia](https://github.com/elysiajs/elysia) to run on the Node.js environment using `uWebSockets.js`.
4+
5+
This adapter brings the raw performance of `uWebSockets.js` to Node.js, providing a server environment that is architecturally consistent with Elysia's native Bun runtime.
6+
7+
## Features
8+
9+
- 🚀 High-performance HTTP server
10+
- 🔌 **Full WebSocket Support**: Includes the powerful `publish/subscribe` API.
11+
- streamed bodies: generator support
12+
- 🦊 Near 1:1 API compatibility with the Bun adapter.
313

414
## Installation
15+
516
```bash
617
bun add @elysiajs/node
718
```
819

920
## Example
21+
1022
```typescript
1123
import { Elysia } from 'elysia'
1224
import { node } from '@elysiajs/node'
1325

1426
const app = new Elysia({ adapter: node() })
15-
.get('/', () => 'Hello Node!')
16-
.listen(3000)
27+
.get('/', () => 'Hello Node!')
28+
.listen(3000)
1729
```
18-
19-
### Note
20-
Node adapter is not feature complete yet. Some features are not supported, such as:
21-
- not support `ws` method

bun.lock

Lines changed: 81 additions & 85 deletions
Large diffs are not rendered by default.

example/index.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Elysia, file } from 'elysia'
21
import { cors } from '@elysiajs/cors'
3-
import { swagger } from '@elysiajs/swagger'
4-
2+
import swagger from '@elysiajs/swagger'
3+
import { Elysia, file } from 'elysia'
54
import { node } from '../src'
65

76
const app = new Elysia({
@@ -12,12 +11,37 @@ const app = new Elysia({
1211
.get('/image', async () => file('test/kyuukurarin.mp4'))
1312
.get('/generator', async function* () {
1413
for (let i = 0; i < 100; i++) {
15-
await new Promise(resolve => setTimeout(resolve, 10))
16-
yield "A"
14+
await new Promise((resolve) => setTimeout(resolve, 10))
15+
yield 'A'
16+
}
17+
})
18+
.get('/stream', async function* () {
19+
for (let i = 0; i < 10; i++) {
20+
yield `Chunk ${i}\n`
21+
await new Promise((resolve) => setTimeout(resolve, 100))
1722
}
1823
})
1924
.post('/', ({ body }) => body, {
2025
type: 'json'
2126
})
22-
.get('/', () => 'ok')
23-
.listen(3000)
27+
.get('/', () => 'Hello from uWebSockets.js!')
28+
.ws('/ws', {
29+
open(ws) {
30+
console.log('WebSocket connected')
31+
ws.subscribe('chat')
32+
ws.publish('chat', 'Someone joined the chat!')
33+
},
34+
message(ws, message) {
35+
console.log('Received message:', message)
36+
ws.publish('chat', `Echo: ${message}`)
37+
},
38+
close(ws) {
39+
console.log('WebSocket disconnected')
40+
}
41+
})
42+
.listen(3000, (server) => {
43+
console.log(`🦊 Elysia is running at ${server.hostname}:${server.port}`)
44+
console.log(
45+
`WebSocket available at ws://${server.hostname}:${server.port}/ws`
46+
)
47+
})

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@elysiajs/node",
3-
"version": "1.3.0",
4-
"description": "Plugin for Elysia for retreiving Bearer token",
3+
"version": "1.4.0",
4+
"description": "High-performance Node.js adapter for Elysia using uWebSockets.js",
55
"license": "MIT",
66
"scripts": {
77
"dev": "tsx --watch ./example/index.ts",
@@ -11,7 +11,7 @@
1111
"release": "npm run build && npm run test && npm publish --access public"
1212
},
1313
"dependencies": {
14-
"@hono/node-server": "^1.14.3"
14+
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.44.0"
1515
},
1616
"peerDependencies": {
1717
"elysia": ">= 1.3.3"

0 commit comments

Comments
 (0)