Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/moody-yaks-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@nest-lab/platform-uws': major
---

Adds platform-uws for uWebSockets.js HTTP/WSS Server

- `UWS` has a much [lower memory footprint](https://socket.io/docs/v4/memory-usage/)
- **socket.io** reintroduced `UWS` in [v4](https://socket.io/docs/v4/server-installation/#usage-with-uwebsockets) (it's back again!)
- Performance is allegedly ["8x that of fastify and at least 10x that of socket.io"](https://github.com/uNetworking/uWebSockets.js#zap-simple-performance)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"@nestjs/core": "10.0.3",
"@nestjs/platform-express": "10.0.3",
"@nestjs/platform-fastify": "10.0.3",
"@nestjs/platform-socket.io": "10.0.3",
"@nestjs/schematics": "10.0.1",
"@nestjs/testing": "10.0.3",
"@nestjs/websockets": "10.0.3",
"@nrwl/tao": "16.4.0",
"@swc/core": "^1.2.218",
"@swc/register": "^0.1.10",
Expand Down
18 changes: 18 additions & 0 deletions packages/platform-uws/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
64 changes: 64 additions & 0 deletions packages/platform-uws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ⚡ @nest-lab/platform-uws
> `HttpAdapter` and `IoAdapter` for [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) (aka UWS)


## ℹ️ Overview

Replaces the `httpServer` with `UWS`. Overrides `IoAdapter` in [@nextjs/platform-socket.io](https://www.npmjs.com/package/@nestjs/platform-socket.io).

### 🤔 Reasoning
- `UWS` has a much [lower memory footprint](https://socket.io/docs/v4/memory-usage/)
- **socket.io** reintroduced `UWS` in [v4](https://socket.io/docs/v4/server-installation/#usage-with-uwebsockets) (it's back again!)
- Performance is allegedly ["8x that of fastify and at least 10x that of socket.io"](https://github.com/uNetworking/uWebSockets.js#zap-simple-performance)

## 📦 Installation

#### npm
```shell
npm i @nest-lab/platform-uws
```
#### yarn
```shell
yarn add @nest-lab/platform-uws
```
#### pnpm
```shell
pnpm i @nest-lab/platform-uws
```

## ⚙️ Usage

```typescript
// ./src/main.ts
import { NestFactory } from '@nestjs/core';
import { UwsHttpAdapter, UwsIoAdapter } from '@nest-lab/platform-uws';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule, new UwsHttpAdapter());
const ioAdapter = new UwsIoAdapter(app);
app.useWebSocketAdapter(ioAdapter);
await app.listen(3000);
}
bootstrap();
```
## 🥅 Project Goals

- [x] Provide basic `HTTPAdapter` backed by `UWS`
- [x] Provide `WebSocketAdapter` backed by `UWS`
- [ ] Provide Advanced `HTTPAdapter` features
- [ ] Test Specifications
- [ ] Test performance vs Express, Fastify and Socket.io


# 👥 Credit
- [@jmcdo29]() @nest-lab scope maintainer
- [@TomBebb]() Original author of [UwsHttpAdapter](https://github.com/TomBebb/nestjs-adapter-uws)
- [@PhearZero]() Experimenting with [UWS](https://github.com/PhearZero/nest-uws)


## 🔊 Rant

`uWebSockets.js` has been around for a while, and it's relationship with `socket.io` has been tenuous at best.
With the advent of the `Zig` language and subsequently the `Bun.js` interpreter, `uWebSockets` has become popular
again. This is even more true in the `Cryptocurrency` space with several large exchanges building exclusively on `UWS`.
63 changes: 63 additions & 0 deletions packages/platform-uws/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@nest-lab/platform-uws",
"version": "0.0.0",
"description": "uWebSockets.js HTTP and Io adapters",
"keywords": [
"uws",
"uWebSockets",
"uWebSockets.js",
"uNetworking",
"socket.io",
"express",
"nestjs"
],
"license": "MIT",
"author": {
"name": "Michael J Feher",
"email": "[email protected]"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "github",
"url": "https://github.com/jmcdo29/nest-lab",
"directory": "packages/platform-uws"
},
"bugs": {
"url": "https://github.com/jmcdo29/nest-lab/issues"
},
"type": "commonjs",
"dependencies": {
"http-status-codes": "^2.2.0",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.30.0"
},
"peerDependencies": {
"@nestjs/common": "^9.0.0 || ^10.0.0",
"@nestjs/core": "^9.0.0 || ^10.0.0",
"@nestjs/platform-express": "^9.0.0 || ^10.0.0",
"@nestjs/platform-socket.io": "^9.0.0 || ^10.0.0",
"@nestjs/websockets": "^9.0.0 || ^10.0.0",
"socket.io": "^4.7.1"
},
"peerDependenciesMeta": {
"@nestjs/common": {
"optional": false
},
"@nestjs/core": {
"optional": false
},
"@nestjs/platform-express": {
"optional": false
},
"@nestjs/platform-socket.io": {
"optional": false
},
"@nestjs/websockets": {
"optional": false
},
"socket.io": {
"optional": false
}
}
}
52 changes: 52 additions & 0 deletions packages/platform-uws/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "platform-uws",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/platform-uws/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/platform-uws",
"tsConfig": "packages/platform-uws/tsconfig.lib.json",
"packageJson": "packages/platform-uws/package.json",
"main": "packages/platform-uws/src/index.ts",
"assets": ["packages/platform-uws/*.md"],
"updateBuildableProjectDepsInPackageJson": true,
"buildableProjectDepsInPackageJsonType": "dependencies"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"cwd": "dist/packages/platform-uws",
"command": "pnpm publish"
},
"dependsOn": [
{
"target": "build"
}
]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/platform-uws/**/*.ts"]
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"command": "node -r @swc/register --test packages/platform-uws/test/index.spec.ts"
},
"configurations": {
"local": {
"command": "node -r @swc/register packages/platform-uws/test/index.spec.ts"
}
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions packages/platform-uws/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/adapters'
2 changes: 2 additions & 0 deletions packages/platform-uws/src/lib/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './uws-http-adapter';
export * from './uws-io-adapter';
Loading